使用.htaccess删除.html或.php URL扩展名不工作


removing .html or .PHP URL extension using .htaccess not working

谁能帮我删除URL中的。html或。php扩展名。

我正在尝试下面的代码在我的php项目,但它不工作。我已经尝试了很多。htaccess代码,但没有帮助我…

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}'.html -f
RewriteRule ^([^/]+)/$ $1.php

Thanks in advance

以前我也遇到过从URL中删除。html或。php扩展名的问题。

我有一个解决方案

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文件,执行下面的代码

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

希望它能帮助你…:)