How to use htaccess to redirect to www and https without having too many redirects error

≡放荡痞女 提交于 2019-12-13 10:25:10

问题


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.

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

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!


回答1:


Redirecting to www:

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

and, redirect http to https:

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


来源:https://stackoverflow.com/questions/32966951/how-to-use-htaccess-to-redirect-to-www-and-https-without-having-too-many-redirec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!