htaccess - 从URL中删除"index.php"并重定向

Iva*_*kir 2 .htaccess redirect

在我的网站上,我使用的是URL地址,例如

http://me.example.com/index.php?p=home
Run Code Online (Sandbox Code Playgroud)

然后我决定使用

http://me.example.com/?p=home
Run Code Online (Sandbox Code Playgroud)

它全部自动工作,没有任何".htaccess"文件.但是包含"index.php"的地址仍然有效.有些网站以"旧"格式链接到我的网站.我希望人们停止使用这种"旧"格式,并在他们使用"旧"格式时将其重定向到"新"格式的URL.我想要做的就是从URL中删除"index.php",并在访问者的浏览器中更改此URL.

anu*_*ava 5

以下是将在DOCUMENT_ROOT下输入.htaccess的代码:

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

RewriteRule ^index\.php/?$ / [L,R=301,NC]
Run Code Online (Sandbox Code Playgroud)

  • 想通了:RewriteRule ^(.*)?index\.php /?$/$ 1 [L,R = 301,NC] (2认同)