1
我想重定向用户到我的主页,如果他们输入任何URL 不以'en'或'fr'开头。我花了几个小时努力完成这项工作,但这对于我脆弱的新手大脑来说太过艰难。目前,如果我试图去无限循环和RewriteCond疯狂,需要帮助
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]
请让我摆脱我的痛苦。干杯!
很抱歉,没有变化(I假设你的意思[NC,L,R = 301]) – Kerans 2010-02-28 00:04:05