疯狂无限循环和RewriteCond,需要帮助

时间:2010-02-27 23:34:51

标签: .htaccess loops infinite-loop mod-rewrite

如果用户输入不是以'en'或'fr'开头的任何网址,我想将用户重定向到我的主页。我花了好几个小时试图完成这项工作,但这对我脆弱的新手大脑来说太难了。目前,如果我试着去

http://mysite.com/fr/produits/

Firefox告诉我重定向永远不会完成。

这就是我想要的:

http://mysite.com/en/whatever/ ==> rewrite as /whatever/index.php?lang=en
http://mysite.com/fr/whatever/ ==> rewrite as /whatever/index.php?lang=fr

http://mysite.com/jp/whatever/ ==> 301 redirect to /fr/accueil/ 
http://mysite.com/whatever/ ==> 301 redirect to /fr/accueil/ 

这是我目前的htaccess。有关详细信息,请参阅内联注释。

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

# Require no www
RewriteCond %{HTTP_HOST} !^mysite\.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [R=301]

# Redirect from root to /fr/accueil/, the URL for the default home page
RewriteRule ^/$ http://mysite.com/fr/accueil/ [NC,R=302]

# Rewrite language path fragment (/fr or /en) as a parameter 
RewriteRule ^fr/accueil/$ /accueil/index.php?lang=fr [QSA,NC] 
RewriteRule ^en/home/$ /accueil/index.php?lang=en [QSA,NC] 
RewriteRule ^fr/produits/$ /produits/index.php?lang=fr [QSA,NC] 
RewriteRule ^en/products/$ /produits/index.php?lang=en [QSA,NC] 

# I'm aware that the rules in this htaccess are re-examined each
# time a rewrite is issued. So the 'fr/accueil/' I'm redirecting to
# will itself be rewritten as /accueil/index.php?lang=fr. That is
# why I'm providing 3 conditions:
# If URI does not start with 'en' AND
# If URI does not start with 'fr' AND
# If QUERY_STRING is not exactly 'lang'
RewriteCond %{REQUEST_URI} !^en/.*$
RewriteCond %{REQUEST_URI} !^fr/.*$
RewriteCond %{QUERY_STRING} !^lang$
RewriteRule ^.*$ fr/accueil/ [NC,R=301]

请把我从痛苦中解救出来。干杯!

1 个答案:

答案 0 :(得分:0)

尝试替换最后一行

RewriteRule ^.*$ fr/accueil/ [NC,R=301]

RewriteRule ^.*$ fr/accueil/ [NCL,R=301]