Remove .php from URL

后端 未结 11 944
生来不讨喜
生来不讨喜 2020-12-15 22:17

Ubuntu 14.04LTS 32bit

LAMP

I know it\'s an old question but..

I need it to remove .php anywhere it finds it from the visible url. It needs to work wi

11条回答
  •  借酒劲吻你
    2020-12-15 22:32

    try this to remove .php extensions completly from your file and to avoid infinite loop:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
    RewriteRule ^ %1 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*?)/?$ $1.php [NC,L]
    

    This code will work in Root/.htaccess, Be sure to change the RewriteBase if you want to place this to a htaccess file in sub directory.

提交回复
热议问题