如何使用htaccess重定向到www和https,而不会出现太多重定向错误 [英] How to use htaccess to redirect to www and https without having too many redirects error

查看:71
本文介绍了如何使用htaccess重定向到www和https,而不会出现太多重定向错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很困,因为这不是我的专长,但是我可以获取以下内容来重定向到www版本,但是一旦我将另一个重定向添加到https(刚购买了ssl并想使用它) !)我收到重定向过多"错误.

I'm really stuck, as this is not my area, but I can get the following to work to redirect to www version, but as soon as I add another redirect to https (just bought the ssl and want to use it!) I get the "too many redirects" error.

这是我工作的.htaccess文件中的内容:

This is what I have in my working .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^talbotandbourne.co.uk
RewriteRule (.*) http://www.talbotandbourne.co.uk/$1 [R=301,L]
ErrorDocument 404 /404.html

那么,如何也将重定向添加到https?

So how do I add a redirect to https as well?

非常感谢您提供的任何帮助.我在整个网站上寻找了该问题的答案,并尝试了其他帖子中的许多建议,但仍然出现错误.我想我可能超重了!

Many thanks for any help received. I've looked all over the site for the answer to this question, and tried many suggestions from other posts, but I still get the error. I think I'm probably punching above my weight!

推荐答案

重定向到www:

RewriteCond %{HTTP_HOST} ^talbotandbourne.co.uk
RewriteRule ^ https://www.talbotandbourne.co.uk%{REQUEST_URI} [R=301,L]

,然后将http重定向到https:

and, redirect http to https:

RewriteCond %{HTTPS} Off [NC]
RewriteRule ^ https://www.talbotandbourne.co.uk%{REQUEST_URI} [R=301,L]

这篇关于如何使用htaccess重定向到www和https,而不会出现太多重定向错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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