htaccess remove index.php? from url

帅比萌擦擦* 提交于 2019-12-20 07:14:42

问题


I need to remove index.php? from URL.

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

To: https://forum.fibaro.com/discover/

I tried everything, but doesn't work :/


回答1:


I think you were trying to mach against URI only so, let me explain something here :

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

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.

Try the following:

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]

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 .



来源:https://stackoverflow.com/questions/49273774/htaccess-remove-index-php-from-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!