htaccess remove index.php? from url

前端 未结 1 1702
后悔当初
后悔当初 2021-01-28 13:12

I need to remove index.php? from URL.

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

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

I t

相关标签:
1条回答
  • 2021-01-28 13:42

    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 .

    0 讨论(0)
提交回复
热议问题