2010-12-13 133 views
0

我想將所有請求重定向到我的網站www.example.com/page.php到www.example.com/1/page.php(其中page.php是任何頁面請求) ,但我是mod_rewrite的新手,無法弄清楚如何做到這一點。Mod_rewrite對子目錄的所有請求

什麼是rewrite_rule和/或條件來做到這一點?

回答

1

試試這個

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ /1/$1 [L,QSA] 
</IfModule> 

我沒有測試它,但它必須努力

+0

如果該文件夾尚未包含,如何修改爲僅重定向?例如。 「/ 1 /任何東西」不應該重定向,但「/任何東西」應該。 – geoidesic 2014-03-11 15:20:20

0
Options +FollowSymlinks 
RewriteEngine On 
RewriteBase/
RewriteRule ^page.php$ 1/page.php [NC,L] 

這可以在htaccess的文件去,但只請求重定向到page.php文件