如果在任何地方使用 .htaccess 找到,重定向并删除 slug

redirect and remove slug if found anywhere using .htaccess

我想删除index.php/

example.com/index.php/apple
example.com/fruits/index.php/apple
example.com/fuits/apple/index.php/ripen
example.com/index.php

在上述任何情况下,我需要通过删除 index.php/

来重定向 url

我试过了

RewriteEngine on 
RewriteBase / 
RewriteRule ^index.php/(.*) / [R=301,L]

但它只适用于上面给定的 urls 中的第一种情况。

使用您显示的示例,请尝试遵循 htaccess 规则文件。确保将文件保存在根目录中。

请确保在测试您的 URL 之前清除您的浏览器缓存。

RewriteEngine ON
##Doing external redirect for index.php here.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php/?$ /? [R=301,L]
##Doing external redirect to remove index.php here.
RewriteRule ^(.*/)?index\.php/(.*) /? [R=301,L]
##Handling home page with internal rewrite here.
RewriteRule ^/?$ index.php [L]