2017-02-13 74 views
2

我有两种类型的网址:.htaccess;重定向过多,如果在.htaccess两个不同的重定向

http://www.example.com/?content=contact_form.php 

http://www.example.com/?content=product.php&id=20 

我改变了我的整个系统的网址是这样的:

http://www.example.com/file/contact_form 

and

http://www.example.com/product/I-m-the-title/20 

当然,我做了301重定向.htaccess告诉谷歌和co。新的网址。

我做了这样的:

# Rewrite URLs 

RewriteEngine On 
RewriteRule ^(ignore)($|/) - [L] 
RewriteRule ^file/([^/]*)$ /?content=$1.php [L] 
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /?content=$1.php&title=$2&id=$3 [L] 


# Redirect old URL to new URL 

RewriteCond %{QUERY_STRING} ^content=contact\_form\.php$ 
RewriteCond %{REQUEST_URI} ^\/$ 
RewriteRule .* http://www.example.com/file/contact_form? [R=301,L] 

RewriteCond %{QUERY_STRING} ^content=product\.php&class=I-m-the-title$ 
RewriteCond %{REQUEST_URI} ^\/$ 
RewriteRule .* http://www.example.com/I-m-the-title/Test/20? [R=301,L] 

我的问题:

它完美工作:http://www.example.com/?content=product.php&id=20

http://www.example.com/?content=contact_form.php我得到它没能打开邮件因为重定向过多。

有人知道我在做什么错吗?我希望有人能够尽快帮助我,因为在Google误解它之前我必须解决它。

回答

1

您的规则导致无限循环,因为它再次重写你的URI到同一位置,并重新覆盖您的内部和外部重定向。要解决这个重写循环,添加以下你的htaccess的顶部

RewriteEngine on 

RewriteCond %{ENV:REDIRECT_STATUS} 200 
RewriteRule^- [L] 
+0

你太棒了。谢谢,非常感谢你! – David