2012-06-26 74 views
1

我有以下.htaccess配置mod_rewrite的配置爲/

RewriteEngine On 
RewriteBase/

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

RewriteRule ^help help.php [L] 
RewriteRule ^home home.php [L] 
RewriteRule ^profile profile.php [L] 
RewriteRule ^index index.php [L] 

RewriteRule ^users/([0-9]+) profile.php?id=$1 [L] 

RewriteRule ^([A-Za-z0-9-]+)?$ profile.php?u=$1 [L] 

現在,每當有人訪問登陸頁面,它們會使用profile.php?u=$1的最後一個規則重定向。

如何更改配置以便www.example.comwww.example.com/映射到index.php而不是profile.php?

回答

1

比賽剛^index規則後的空字符串或單斜槓:

RewriteRule ^help help.php [L] 
RewriteRule ^home home.php [L] 
RewriteRule ^profile profile.php [L] 
RewriteRule ^index index.php [L] 
# Match root request with optional slash 
RewriteRule ^/?$ index.php [L] 
+0

可惜只有8分鐘後,我可以接受的答案。謝謝一堆! – kapeels

0

我會建議不要做這種方式。

相反,只要用戶這個

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

這將發送所有的請求到index.php頁面,從那裏創建一個router.php並傳遞請求到該頁面,使用PHP。

,但如果你做什麼,只是添加

RewriteRule ^/?$ index.php [L] 

像邁克爾建議。

下面是一個簡單的工具來測試您的規則,如果你想

Apache RewriteRule tester