0
我目前的.htaccess如下。在不影響其他規則的情況下重定向首頁
# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
RewriteEngine on
# Send request via index.php (if it's not an existing file/folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
我想重定向我的主頁到另一個域名,但維護所有/子/目錄。 因此改變了規則如下。
# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
RewriteEngine on
# Send request via index.php (if it's not an existing file/folder)
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#redirect
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://example.com/ [L,R=301]
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
現在所有的/子/目錄越來越個內服務器錯誤。日誌表明它正在循環中。
有什麼想法?
是的,這是正確的+1 – anubhava
感謝@croises。 「RewriteRule^- [L]」這條規則有什麼用? – Arvin
首先我用'-d'(用於目錄)和'-f'(文件)測試它們是否存在。 '^'是所有情況下的簡稱。如果在這種情況下文件或目錄存在,'[L]'標誌將導致mod_rewrite停止處理規則集。 – Croises