htaccess 删除 index.php?来自 url

htaccess remove index.php? from url

我需要删除 index.php?来自 URL.

发件人:https://example.com/index.php?/discover/

收件人:https://forum.fibaro.com/discover/

我什么都试过了,但还是不行:/

我认为您只是尝试针对 URI 进行 mach,让我在这里解释一下:

https://example.com/index.php?/discover/

这部分 index.php 是 URI ,然后是 ? 然后是 /discover/ ,最后一部分是查询字符串所以要匹配它你可以使用 QUERY_STRING or THE_REQUEST Server-Variables 根据您的需要,但是当使用 REQUEST_URI 时,您只匹配 URI 部分。

尝试以下操作:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,7}\s/index\.php\?\/(.*)\sHTTP.*$
RewriteRule ^index\.php$  /%1? [L,R=301]
RewriteRule !^index\.php$  /index.php?%{REQUEST_URI} [L]

上面的代码会将 https://example.com/index.php?/discover/ 从外部重定向到 https://example.com/discover/,然后再将其重定向到同一路径。

注意:清除浏览器缓存然后测试。