2012-04-04 91 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