本文介绍了使用.htaccess删除.html或.PHP URL扩展名不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能帮助我删除URL中的.html或.php扩展名.
can anyone help me to remove .html or .php extension in URL.
我正在我的php项目中尝试以下代码,但无法正常工作.我已经尝试了很多.htaccess代码,但没有任何帮助..
I am trying this below code in my php project, but it is not working.I have tried so many .htaccess codes, but nothing helps me..
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.php
预先感谢
推荐答案
以前,我还遇到了删除.html或.php扩展名表格URL的问题.
Previously I also faced problem with removing .html or .php extension form URL.
我在这里有解决方法
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
将以上代码放入.htaccess文件中,以上代码适用于.php文件.对于.html文件,请通过以下代码
put the above code in .htaccess file, above code is for .php files.for .html files go through the below code
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.html to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]
我只是将.php替换为.html
I just replaced the .php with .html
希望对您有帮助..:)
Hope it helps You.. :)
这篇关于使用.htaccess删除.html或.PHP URL扩展名不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!