2012-04-04 89 views
2

在我的網站,我是使用的URL地址,如htaccess的 - 從URL中移除「的index.php」和重定向

http://me.example.com/index.php?p=home 

於是我決定用

http://me.example.com/?p=home 

這一切都自動的工作沒有任何「.htaccess」文件。但包含「index.php」的地址也仍然有效。有些網站以「舊」格式鏈接到我的網站。我希望人們停止使用這種「舊」格式,並在它們使用「舊」格式時將它們重定向到「新」格式的URL。我想要做的就是從URL中刪除「index.php」,並在訪問者的瀏覽器中更改此URL。

+0

可能重複:http://stackoverflow.com/questions/9764828/htaccess-redirect-to-remove-index-php – clmarquart 2012-04-04 13:23:33

回答

5

這裏是一個將在.htaccess去下DOCUMENT_ROOT代碼:

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

RewriteRule ^index\.php/?$/[L,R=301,NC] 
+0

我認爲這將是一條線......但確定:)謝謝:) – 2012-04-15 22:25:25

+0

如何保留一個URL路徑,仍然這樣做?例如example.com/folder/index.php=example.com/foler/ – BenJamin 2013-01-23 23:05:08

+2

計算出來:RewriteRule ^(。*)?index \ .php /?$/$ 1 [L,R = 301,NC] – BenJamin 2013-01-23 23:25:59