使用.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.. :)