简体   繁体   English

从/index.html重定向

[英]Redirect from /index.html

At .htaccess I have such a rule to redirect from site.com to www.site.com: 在.htaccess,我有这样一条规则,可以从site.com重定向到www.site.com:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^site.com$
RewriteRule ^(.*)$ http://www.site.com/$1 [L,R=301]

It works fine, but also I need to redirect from site.com/index.html to http://www.site.com I have add this one: 它工作正常,但我还需要从site.com/index.html重定向到http://www.site.com,我已经添加了以下内容:

RewriteCond %{HTTP_HOST} ^site.com/index.html$
RewriteRule ^(.*)$ http://www.site.com/$1 [L,R=301]

But it doesn't work :( Anybody help please? 但这不起作用:(任何人都可以帮忙吗?

Do this: 做这个:

RewriteEngine on

RewriteRule ^index.html$ / [R=301,L]

RewriteCond %{HTTP_HOST} ^site.com$
RewriteRule ^(.*)$ http://www.site.com/$1 [L,R=301]

Do not forget to clear your browser's cache! 不要忘记清除浏览器的缓存! Before trying the above. 在尝试以上方法之前。

try putting your second condition before the first one and it should work. 尝试将第二个条件放在第一个条件之前,它应该起作用。

EDIT: 编辑:

try this as your first rule: 将此作为您的第一条规则:

RewriteRule ^site.com/index.html$ http://www.site.com [L,R=301]

(i guess your your 2nd rule is wrong._ (我想您的第二条规则是错误的。_

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM