如何在URL中隐藏特定的文件扩展名(html& php)? [英] How to hide specific files extensions (html & php) in URL?

查看:65
本文介绍了如何在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

这篇关于如何在URL中隐藏特定的文件扩展名(html& php)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆