2014-11-06 30 views
1

我有這兩個htaccess重寫(我從別處剔除),它們獨立地爲我的站點執行X或Y操作。我無法弄清楚的是如何編寫它,以便兩個功能都能正常工作。htaccess將根合併到url並隱藏index.php

重定向失蹤 「www」 的所有請求:

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

重定向含有 「的index.php」 的所有請求:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?) 
RewriteRule^/%1 [R=301,L] 

此外,前者功能的工作原理重寫的例子。 com到www.example.com。但是,我在這個根目錄的子目錄中有另一個站點,它有自己的「獨立」網址。但該函數也會將www.anotherexample.com上的該網址重寫爲www.example.com/anotherexample。

如何將這些合併爲一個可操作的函數,而無需重寫我的子目錄站點url?提前致謝。

+0

你有你的htaccess文件的其他規則? – 2014-11-06 21:25:18

回答

0

你也可以在根的.htaccess這些組合規則:

RewriteEngine On 

RewriteCond %{HTTP_HOST} ^example\.com$ [NC] 
RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 

RewriteCond %{THE_REQUEST} /index\.php [NC] 
RewriteRule ^(.*?)index\.php$ /$1 [L,R=301,NC,NE] 
+1

這樣做,anubhava。 :) 非常感謝! – user3569292 2014-11-06 21:44:54