Hide extension and variables using .htaccess

后端 未结 2 1012
清歌不尽
清歌不尽 2021-01-25 12:56

How can I hide the file\'s extension and the GET variables via .htaccess in one line?

This code doesn\'t work:

...
RewriteRule ^(.*)$ $1.php [L]
RewriteR         


        
相关标签:
2条回答
  • 2021-01-25 13:18

    This is a better for static pages. You only need to change "index" as your file and change get element according to yours. In example, there is "id" element.

    RewriteEngine On
    RewriteRule ^((?:[a-zA-Z0-9_-]|%20)+)/?$ index.php?id=$1
    
    0 讨论(0)
  • 2021-01-25 13:35

    You need to add a few conditions to the first rule to keep it from looping, you can try changing it to:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*)$ $1.php [L]
    

    Then go continue with your second rule, which loks fine the way it is.

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