Copy link to clipboard
Copied
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"
annpoulson.com redirected you too many times.
Copy link to clipboard
Copied
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]
Copy link to clipboard
Copied
Ohhhh myyyy goshhhh thanks so much! That worked! Thanks so much!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
My rule of thumb with www prefix is use whichever one gives you the most Google search results.
Type your site into the browser address bar like this:
site: www.yourdomain.com
or site:yourdomain.com
And be sure to tell Google Console your preferred URL is HTTPS
Set your preferred domain (www or non-www) - Search Console Help