将旧网址重写为漂亮的网址,并使用.htaccess将旧网址重定向到新网址

编程入门 行业动态 更新时间:2024-10-21 20:40:55
本文介绍了将旧网址重写为漂亮的网址,并使用.htaccess将旧网址重定向到新网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在.htaccess设置上遇到了一些问题. 我的网站主页网址为: www.domain/b/zh-CN index.php ,然后使用mod_rewrite创建漂亮的url: www.domain. com/en

I have some problems with .htaccess settings. My Website home page url is : www.domain/b/en/index.php ,and I use mod_rewrite to create pretty url : www.domain/en

这是我对漂亮网址的重写规则(有效):

This is my rewrite rules for pretty urls (It works):

RewriteRule ^en/(.*)$ /b/$1 [L,QSA,NC,PT]

这是我想要的漂亮网址,但是当我将旧网址"重定向到新网址时,就会出现一些问题.

That's pretty urls what I want, but when I redirect "old urls" to new urls, there are some problems.

我的Chrome浏览器显示"www.domain redirected you too many times."

My Chrome browser shows "www.domain redirected you too many times."

这是我的旧网址重定向到新规则:

This is my old urls redirect to new rule:

RewriteRule ^b/en/(.*)$ /en/$1 [NC,L,R=301]

推荐答案

这是一个通用的两部分问题.您需要将原始请求重定向到更漂亮的一个:

This is a generic 2-part problem. You'll need to redirect the raw request to prettier one:

RewriteRule ^en/(.*)$ /b/en/$1 [L,QSA,NC] RewriteCond %{THE_REQUEST} ^GET\ /b/(en)/(\S*) [NC] RewriteRule ^b/ /%1/%2 [R=301,L]

在测试新规则之前,请确保清除浏览器的缓存.

Be sure to clear your browsers' cache before testing the new rules.

更多推荐

将旧网址重写为漂亮的网址,并使用.htaccess将旧网址重定向到新网址

本文发布于:2023-10-31 15:52:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546556.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网址   重写   到新   重定向   漂亮

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!