.htaccess重定向不正确

时间:2015-11-06 15:47:22

标签: .htaccess mod-rewrite redirect url-rewriting

我想通过以下方式重定向我的网页:

www.example.com/index.cfm?locale=it -> www.example.com/it

我想在输入时访问同一页面:

www.example.com/it

我写了一个htaccess文件,但它会导致重定向循环。这是文件:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#REWRITE RULES
#---------------------

RewriteCond %{QUERY_STRING} ^locale=(it|en|fr|de|es)$
RewriteRule ^index\.cfm$ %1? [R=302,L]

RewriteCond %{REQUEST_URI} !^index\.cfm
RewriteRule ^(it|en|fr|de|es)/?$ index.cfm?locale=$1 [L]

</IfModule>
你可以帮我解决一下吗? 感谢!!!

2 个答案:

答案 0 :(得分:0)

试试这个:

//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com/it[nc]
RewriteRule ^(.*)$ http://www.example.com/it/$1 [r=301,nc]

//301 Redirect Old File
Redirect 301 www.example.com/index.php?locale=it www.example.com/it

//301 Redirect Entire Directory
RedirectMatch 301 www.example.com/index.php?locale=it(.*) www.example.com/it/$1

答案 1 :(得分:0)

你可以这样试试。

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
Rewrite ^ - [L]

RewriteCond %{THE_REQUEST} ^GET\ /index\.cfm\?locale=(it|en|fr|de|es)
RewriteRule ^ %1? [R=302,L]

RewriteRule ^(it|en|fr|de|es)/?$ index.cfm?locale=$1 [L]