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

问题描述:

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]

我是新手,我已经编写了这段代码,并且显示**内部服务器错误。请

I am newbie and I have written this code and it is showing **"INTERNAL SERVER ERROR".Please help me with this!

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

You can replace your current code by this one in your htaccess (which has to be in root folder)

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

Also, please make sure you enabled mod_rewrite in your Apache configuration