How do I remove the '.php' extension from URLs?

会有一股神秘感。 提交于 2019-12-08 05:33:45

问题


This is where the PHP files are:

ts1.WEBSITENAMEHERE.biz/cp/

The .htaccess file is also in this folder. I want to remove the '.php' from 'FILENAME.PHP'.

This is my current '.htaccess' file:

Options +FollowSymlinks
RewriteEngine on 
RewriteBase /cp
RewriteRule ^(.*)/$ $1.php

But it is not working. Why is this?


回答1:


RewriteEngine on
RewriteBase /cp/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !\.php$
RewriteRule .* $0.php [L]



回答2:


Create a .htaccess file in the DocumentRoot dir. Add the following code in that file...

##############
RewriteEngine On
RewriteCond %{REQUEST_URI} !^(.*)\.(.*)$
RewriteRule ^(.*)$ %{REQUEST_URI}.php [R]
#############

mod_rewrite should be enabled for this to work.




回答3:


    Options +FollowSymlinks
    RewriteEngine on 
    RewriteBase /cp
    RewriteRule ^(.*) $1.php

I use this checker: http://htaccess.madewithlove.be



来源:https://stackoverflow.com/questions/11042874/how-do-i-remove-the-php-extension-from-urls

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