如何在URL中隐藏特定的文件扩展名(html& php)?

时间:2014-12-29 07:05:50

标签: .htaccess

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1.php [L]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)/$ $1.html [L]

我是新手,我写了这段代码,它显示**“内部服务器错误”。请帮我这个!

1 个答案:

答案 0 :(得分:0)

您可以在htaccess(必须位于根文件夹中)中替换当前代码

Options -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [NC]

RewriteCond %{REQUEST_URI} ^/(.+?)/$
RewriteCond %{DOCUMENT_ROOT}/%1\.html -f
RewriteRule ^ /%1.html [L]

RewriteCond %{REQUEST_URI} ^/(.+?)/$
RewriteCond %{DOCUMENT_ROOT}/%1\.php -f
RewriteRule ^ /%1.php [L]

另外,请确保在Apache配置中启用 mod_rewrite