2017-02-13 52 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