如何阻止.html出现在网址中?

时间:2014-06-30 09:33:29

标签: html

这可能是一个非常简单的修复方法,但是如何设置它以便当你访问我的网站(www.skidsfordays.com)时,它会出现这种情况,而不是www.skidsfordays.com/index.html然后网站上的每个页面都有.html。我怎样才能解决这个问题?感谢。

2 个答案:

答案 0 :(得分:5)

在您的Web根目录中创建.htaccess并在其中添加以下行:

Options +Multiviews

- >完成。

这意味着,服务器不需要文件扩展名(例如:.html,.php)来加载所请求的文件。

答案 1 :(得分:0)

要隐藏index.html,请在 .htaccess 文件中的以下代码中添加以下代码,我们会将index.html网址重写为您的网站域名:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com [OR]
RewriteCond %{REQUEST_URI} /index\.html$
RewriteRule (.*?)(index\.html)?$ http://yoursite.com$1 [NE,R=301,L]

要隐藏.html扩展程序,请尝试以下代码

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]