我想通过htaccess文件301重定向以下URL
这意味着我需要强制SSL(https)版本,并强制整个网站的www。
另外我还想301重定向index.html到https和www版本的主页网址。
我想301重定向以下URL:
https://www.example.com/index.html
https://example.com/index.html
https://example.com
http://www.example.com/index.html
http://example.com/index.html
http://www.example.com
http://example.com
www.example.com
example.com
结束日期
“https://www.example.com”
除此之外,我需要将该网站的所有URL重定向到https://www版本,如下所示:
“https://www.example.com/new-site.html”
下面是我现在使用的:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]
RewriteBase /
RewriteRule ^index\.html$ / [NC,R,L]
但是上面的规则似乎给予了我一个301---〉302----200 ok重定向2个url的/index. html和301为其余的。
它给出了302,来自:
“https://www.example.com/index.html”
到这
“https://www.example.com/“
- 谢谢-谢谢
2条答案
按热度按时间o7jaxewo1#
您可以在一个规则中完成所有这些操作:
uinbv5nw2#
好吧,我自己想明白了:
下面是它的工作原理,只需要在最后一条规则中添加R=301,而不仅仅是R