htaccess删除index.php?从网址 [英] htaccess remove index.php? from url
问题描述
我需要删除index.php吗?
I need to remove index.php? from URL.
来自: https://example.com/index.php?/discover/
收件人: https://forum.fibaro.com/discover/
我尝试了一切,但没有用:/
I tried everything, but doesn't work :/
推荐答案
我认为您正在尝试针对URI只有这样,让我在这里解释一下:
I think you were trying to mach against URI only so, let me explain something here :
https://example.com/index.php?/discover/
这部分 index.php
是URI,然后有是?
,然后是 / discover /
,最后一部分是查询字符串,因此可以与之匹配 QUERY_STRING或THE_REQUEST
服务器变量根据您的需要,但是在使用 REQUEST_URI
时,您只能匹配URI部分。
This part index.php
is URI , then there is ?
and after that is /discover/
, the last part is query string so to match against it you could use QUERY_STRING or THE_REQUEST
Server-Variables according to what you need but when using REQUEST_URI
you match only against URI part.
尝试以下操作:
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/
从外部,然后再次将其重定向到同一路径。
The code above will redirect https://example.com/index.php?/discover/
to https://example.com/discover/
externally and then redirect it again to same path .
注意:清除浏览器缓存,然后对其进行测试。
Note: clear browser cache then test it .
这篇关于htaccess删除index.php?从网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!