将旧网址重写为漂亮的网址,并使用.htaccess将旧网址重定向到新网址 [英] Rewriting old urls to pretty urls, and redirect old urls to new with .htaccess
问题描述
我在.htaccess
设置上遇到了一些问题.
我的网站主页网址为: http://www.domain.com/b/zh-CN index.php ,然后使用mod_rewrite
创建漂亮的url: http://www.domain. com/en
I have some problems with .htaccess
settings.
My Website home page url is : http://www.domain.com/b/en/index.php ,and I use mod_rewrite
to create pretty url : http://www.domain.com/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.com redirected you too many times.
"
My Chrome browser shows "www.domain.com 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将旧网址重定向到新网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!