Regex 使用htaccess删除/index.php链接?

Regex 使用htaccess删除/index.php链接?,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我可以这样打开我的网站: www.mysite.com www.mysite.com/index.php 或者像这样: www.mysite.com www.mysite.com/index.php 我想创建一个重定向到的htaccess规则。但我所有的尝试都有其他副作用。我试过: Redirect index.php home.php RewriteRule ^index.php?$ home.php [NC,L] RewriteRule ^index.p

我可以这样打开我的网站:

www.mysite.com
www.mysite.com/index.php
或者像这样:

www.mysite.com
www.mysite.com/index.php
我想创建一个重定向到的htaccess规则。但我所有的尝试都有其他副作用。我试过:

Redirect index.php    home.php
RewriteRule    ^index.php?$    home.php    [NC,L]
RewriteRule    ^index.php/?$    redirect_to_home.php    [NC,L]
但所有这些都打乱了最初的index.php调用。所以它确实重定向了,但是正常的mysite.com链接不再起作用了


有什么想法吗?

使用此重定向规则从任何路径中删除
/index.php

RewriteEngine On

RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]
RewriteRule ^ %1 [L,R=301,NE]

你能试试下面的吗

RewriteEngine On
RewriteCond  %{REQUEST_FILENAME} -f
RewriteCond %{THE_REQUEST} index\.php
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$
RewriteRule ^ %1 [R=301,L]
说明:

  • 启用
    重写引擎
    ,使规则生效
  • 通过
    RewriteCond
    REQUEST\u FILENAME
    提及条件,检查浏览器中提及的文件是否存在
  • 然后检查_请求是否包含完整的请求细节(包括URL和GET/POST方法),如果其中包含index.php
  • 现在检查
    REQUEST\u URI
    是否在请求的url中具有
    index\.php
    ,将之前的所有内容保存到临时缓冲内存中,以便稍后检索其值(基本上是其域名)
  • 最后,在
    RewriteRule
    中,根据要求将index.php的完整URL重定向到域名(R=301表示浏览器端的永久重定向)