2013-02-26 20 views
0

我試着去了解一些基本的重寫的東西,所以我發現那位是一樣的東西:使用通配符的RewriteCond結合的標誌嗎?

RewriteCond %{HTTP_HOST} ^example.(.+)$ [NC] 
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] 

和:

RewriteCond %{HTTP_HOST} ^(www2.example.de|example.de)$ [NC] 
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] 

但如果我結合它像

RewriteCond %{HTTP_HOST} ^(www2.example|example).(.+)$ [NC] 

我得到由於重定向過多導致內部服務器錯誤。

所以,我怎麼能結合使用或內部消除www和不同域的結尾:

RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR] 
RewriteCond %{HTTP_HOST} ^www.example.name$ [NC,OR] 
RewriteCond %{HTTP_HOST} ^example.name$ [NC,OR] 
RewriteCond %{HTTP_HOST} ^www.example.de$ [NC,OR] 
RewriteCond %{HTTP_HOST} ^example.de$ [NC] 
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] 

我覺得應該是很簡單,但我只是不明白這一點...

+0

「結合」他們做什麼?請解釋你想用mod_rewrite實現什麼? – 2013-02-26 11:31:17

+0

第一COND重定向到example.anything www.example.com和第二COND重定向www2.example.de或example.de到www.example.com,現在我想是這樣(「WWW」 |「」)。例如(*)將被定向至www.example.com。 – Karim 2013-03-16 00:33:12

+0

或者,也許更容易:在我最後的代碼塊我有5個的RewriteCond並希望做同樣在1周...的RewriteCond – Karim 2013-03-16 00:34:42

回答

1

五編碼可以結合在一個單一的,像這樣:

RewriteCond %{HTTP_HOST} ^example\.com$    [NC,OR] 
RewriteCond %{HTTP_HOST} (?:www\.)?example\.(name|de) [NC] 
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] 
+0

感謝您的回答,但如果我不喜歡這樣,我得到相同的:錯誤310(淨值:: ERR_TOO_MANY_REDIRECTS)..任何其他想法? – Karim 2013-03-18 15:22:45

+0

我的錯誤。我包含了「www.example.com」。在我的答案中添加了一行。 – 2013-03-18 15:28:41

+0

酷,非常感謝,現在我終於明白了太多次重定向錯誤...! – Karim 2013-03-19 18:41:55