Removing the PHP file type extension

隐身守侯 提交于 2020-01-05 05:34:19

问题


I'm using this in my top level .htaccess to remove the PHP file type extension on my *.php files.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

But I have discovered it also prevents my browser from calling the index.php page in my sub-directories. I need to include /index.php explicitly in the URL.

Is there a better way to remove the PHP file type extension on my *.php files?


回答1:


here you go:

RewriteEngine  on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

or try this one. This should also work in a sub-directory path:

RewriteEngine  on
RewriteRule ^(.*)$ $1.php

or in an if clause

<IfModule mod_rewrite.c>
    RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>


来源:https://stackoverflow.com/questions/41019584/removing-the-php-file-type-extension

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