2013-05-02 166 views
2

我最近更改我的index.html index.php - 我想能夠做一個重定向來反映這一點,然後也是一個重寫,強制foo.com/index.php只是foo.com/並讓它訪問.php文件。我如何htaccess的index.html index.php和index.php重定向到/

我也有一個單獨的網站,即bar.com位於foo.com下的子目錄中,我想保持不受影響。

這是我的東西,這會導致重定向循環:

RedirectMatch 301 ^/index.html?$ /index.php 
Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/ 
RewriteRule ^(.*)index\.php$ /$1 [R=301,L] 

有沒有辦法做到這一點?謝謝!

回答

5

RedirectMatch指令匹配內部重定向,是以/請求,並將其重定向到/index.html,那麼它獲得通過URL文件映射管道又把因而您的重定向指令匹配之後。

您可以嘗試包括:

DirectoryIndex index.php 

防止這種自動的內部重定向。你也應該使用%{THE_REQUEST}與之相匹配的index.html文件就像你與index.php做:

Options +FollowSymLinks 
DirectoryIndex index.php 

RewriteEngine on 

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

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

或者你可以完全的index.php繞過:

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

絕對美麗。正是我想要的/需要的。太感謝了! – 2013-05-03 13:20:00

相關問題