【发布时间】:2021-03-23 00:15:48
【问题描述】:
我想通过 htaccess 文件对以下 URL 进行 301 重定向
这意味着我需要强制使用 SSL(https) 版本并在整个网站上强制使用 www。
另外我还想将index.html 301重定向到https和www版本的首页url。
我想301重定向以下网址:
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 个带有 /index.html 的 url 和 301 的其余部分。
它给出一个 302 来自:
“https://www.example.com/index.html”
到这里
“https://www.example.com/“
谢谢。
【问题讨论】:
-
欢迎来到 SO。请添加明确的 URL 详细信息示例,例如您希望从哪个 url 重定向/重写的 url,方法是将它们包装在 CODE TAGS 中,以便更好地理解您的问题。
-
对不起,我会编辑这个
-
对不起,我在移动设备上,没有完整的功能。
-
评论不代表问题/努力,如前所述,请更新您的问题,谢谢。
-
谢谢。现在完成。唷