2012-11-13 57 views
1

舊網站重定向:
www.example.com(默認)htaccess的 - 重寫&沒有導致循環

新網站:
example.com(默認)
和一新的語言..
es.example.com

目前舊網站:
www.example.com/this-page.php

通緝的新網站(網址乾淨):
example.com/this-page
es.example.com/esta-pagina

到目前爲止,我有這樣的:

RewriteCond %{HTTPS} !=on 
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
RewriteRule^http://%1%{REQUEST_URI} [R=301,L] 

RewriteRule ^this-page/?$ this-page\.php?lang=$1 
RewriteRule ^esta-pagina/?$ this-page\.php?lang=$1 


**的$ _GET [ '郎']是內部產生取決於example.com或es.example.com是否擊中。

問題:

如何我還可以添加一個類似的重定向:
重定向301 /this-page.php http://example.com/this-page
...這不會造成死循環?

+0

爲什麼你不能使用一個額外的RewriteCond爲evaulates的HTTP_HOST規則? – arkascha

+0

@arkascha我重寫虛 - 你可以給我如何做到這一點的線索? – Leon

回答

1

如何我還可以添加一個類似的重定向:
重定向301 /this-page.php http://example.com/this-page
...這不會造成死循環?

你需要來匹配實際的請求,而不是URI。當重寫引擎遍歷規則時,URI將會改變。

RewriteCond %{THE_REQUEST} ^(GET|HEAD|POST)\ /this-page\.php(\?|\) 
RewriteRule^/this-page [L,R=301] 
+0

感謝您的解釋 - 這是完全正常工作。 – Leon

0

另外值得注意的是,如果您使用的是CDN喜歡的CloudFlare的%{} HTTPS檢查會給你無限循環錯誤。如果你是一個CloudFlare的用戶就需要更換的RewriteCond%{} HTTPS =與此:

RewriteCond %{HTTP:X-Forwarded-Proto} =http