Skip to main content
Nantaar
Participant
March 10, 2019
Question

Redirect Issues

  • March 10, 2019
  • 1 reply
  • 886 views

Hi all,

I am having a heck of a time getting a redirect to work and even knowing what type of redirect I should be using. I just bought an SSL certificate that requires a redirect. My hosting provider said to use a .htaccess redirect. The server I am using is Unix. The website is coded in html. I am trying to go from annpoulson.com to https://annpoulson.com. I have tried several code and none have worked. I'm not sure if I should be using a 301 or 302 redirect and what the correct code is...

The current code in the .htaccess files says:

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule ^(.*)$ https://annpoulson.com/$1 [R=301,L]

But the website says to many redirects when I try to load it in Chrome"

This page isn’t working

annpoulson.com redirected you too many times.

ERR_TOO_MANY_REDIRECTS

I have tried clearing cookies etc. and same error. Thanks for any help anyone can offer.
This topic has been closed for replies.

1 reply

Nancy OShea
Community Expert
Community Expert
March 10, 2019

How many .htaccess files are currently on your server? 

The page is not redirecting correctly.

Try this:

# Remove www from any URLs that have them:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.

RewriteRule ^(.*)$ http://annpoulson.com/$1 [R=301,L]

#change http to https

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Nancy O'Shea— Product User & Community Expert
Nantaar
NantaarAuthor
Participant
March 10, 2019

Ohhhh myyyy goshhhh thanks so much! That worked! Thanks so much!

Legend
March 10, 2019

You can combine those two rules also like this:

force https and non www. URLs:

RewriteCond %{HTTPS} off [OR]

RewriteCond %{HTTP_HOST} ^www\. [NC]

RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]

RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

alternatively force https and www. URLs:

RewriteCond %{HTTPS} off [OR]

RewriteCond %{HTTP_HOST} !^www\. [NC]

RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]

RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]

Its a good idea to make sure all URLs are served consitently over either non www. or www. URLs to avoid 'canonical issues'  as well as obviously serving pages over https.

Paul-M - Community Expert