Is it possible to direct HTTP www 301 to HTTPS non www?
-
I have a question that has been stumping me and if someone could help I would gladly buy your coffee for a month.
I have a website that used to be www and http a year or two ago. Now it is https and non www. A lot of my older links point to the www and http version of my site. This results in two 301 redirects.
I.e.
A link on another site to my site points to http://www.mysite.com
The network waterfall shows:
http://www.mysite.com 301 -> http://mysite.com
http://mysite.com 301 -> https://mysite.com
https://mysite.com (finally)
**2 part question. **
**--Do you think that this two 301 redirect hop would affect SEO performance? I can see it did affect page authority through Moz. **
--Is there away around this? I.e. to redirect http:// AND http://www directly to https:// with no hops in between.
Thank you!
-
Hello,
With Wordpress I believe you can just add it under all that code, like below. After you make the changes, I would suggest opening a private browser window or clearing your cache and make sure the site, pages and redirects are coming up as intended, since .htaccess changes can sometimes be a bit hairy and cause the site to white screen or cause infinite loops.
BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]END WordPress
RewriteEngine On
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://example.com/$1 [R=301,L]RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301] -
Thank you so much for your quick answer. I made it my mission to become a DNS, htaccess and redirect expert over the next two weeks as it has been my Achilles heel for far too long. How would you write this with an htaccess file hosted in a on a server that's running Wordpress (WP Engine specifically)?
This is the default WP htaccess file:
# BEGIN WordPress <ifmodule mod_rewrite.c="">RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]</ifmodule> # END WordPress
-
Hello,
I have not heard of this kind of setup affecting SEO performance, but I could be wrong. Even if you didn't have the old URL structure and incoming links, I would still have these redirects to ensure all the current site links are only accessible via one type of URL, https, non-www.
These are the two redirects I have used in my .htaccess file to achieve what you are looking for. In the network I only see as one redirect listed though, not two. Hope this helps.
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://example.com/$1 [R=301,L]RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301] -
You should be able to change this in your .htaccess file.
RewriteEngineOn
RewriteCond%{SERVER_PORT}80
RewriteRule^(.*)$https://yourdomain.com/$1 [R=301,L]
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
301 Old domain with HTTPS to new domain with HTTPS
I am a bit boggled about https to https we redirected olddomain.com to https://www.newdomain.com, but redirecting https://www.olddomain.com or non-www is not possible. because the certificate does not exist on a level where you are redirecting. only if I setup a new host and add a htaccess file will this work. What should I do? just redirect the rest and hope for the best?
Intermediate & Advanced SEO | | waqid0 -
CNAME record for WWW to Non-WWW Vs. 301?
I was just chatting with the person who set up our site on our domain hosting and they said they added in a CNAME record to transfer the www version of my site to the Non-www version. Shouldn't this be set up as a 301 redirect? I have hundreds of links built to the www version and only a few to the non-www version. Or Could I just add in a 301 in addition to the CNAME record? This is not my wheelhouse and need a little advice. Thanks in Advance.
Intermediate & Advanced SEO | | photoseo10 -
Http to https what should one look out for
Hi, we are moving our site from http to https and would like to know what should one look out for. What are the things that can go wrong, and what is the best way to go about it. Regards Tai
Intermediate & Advanced SEO | | Taiger0 -
Pages that 301 redirect to a 404
We are going through a website redesign that involves changing URL's for the pages on our site. Currently all our pages are in the format domain.com/example.html and we are moving to stip off the .html file extension so it would just be domain.com/example We have thousands of pages as the site deals with news so building a redirect for each individual page isn't really feasible. My plan is to have a generic rewrite rule that redirects any page that ends .html to the stripped off version of this. A problem I can see with this is that it will also redirect pages that don't exist. So for example, domain.com/non-existant-page.html would 301 to domain.com/non-existant-page which would then return a 404 status. What would the SEO repercussions be for this? Obviously if a page doesn't exist already then it shouldn't show up in the search engine indexes and shouldn't be a problem but I'm a bit worried about how old pages that currently legitimately 404 will be treated when they start to 301 redirect to a 404 instead. Not sure if there any other potential issues from this that I've missed either? Thanks!
Intermediate & Advanced SEO | | sbb0240 -
Possible for SERP appearance to change on a keyword?
Hi, We're currently working with a brand name which happens to be the name of a small town in the US (126 population). When Googling the brand / town name, there's a map on the right-hand side of the SERP. (Google Maps, with the town highlighted) We're based in Sweden, and this is even showing up on a search on the Swedish Google. I'm wondering; Is it possible for the map to "be removed" as our brand becomes more known? Does anyone have any similar experiences? Is it a better idea to just switch brand name?
Intermediate & Advanced SEO | | JSTRANDELL0 -
301 redirect help
Hey guys, I normally work in WordPress and just use a 301 redirect plugin. I bought a site and rather than maintain two similar ones have decided to redirect one to the other. I am having trouble with the .htaccess file. Here is an example. These are two redirects: redirect 301 /category/models/next/2
Intermediate & Advanced SEO | | DanDeceuster
redirect 301 /category/models I want both of these URLs to redirect to the same URL of the new site. However, the /category/models is the only one working. It redirects to the new page just fine. The /category/models/next/2 is redirecting to nearly the same URL on the new site, only it is adding /next/2 to the end and that is bringing up a 404. Why is it adding /next/2 to the new URL? How can I fix this? There are several doing this. Help appreciated!0 -
Www and non www how to check it.......for sure. No, really, for absolutely sure!!
Ok, I know it has been asked, answered, and re-asked but I am going to ask for a specific reason. As you know, anyone who is a graphic designer or web developer is also an expert in SEO....Right???
Intermediate & Advanced SEO | | RobertFisher
I am dealing with a client who is clinging to a developer but wants us to do the SEO on a myriad of sites. All connect to his main site via links, etc. The main site was just redeveloped by a developer who claims extensive SEO knowledge. The client who referred me to them is getting over twenty times the organic clients they are and is in a JV with the new client. Soooo, I want to show them once and for all they are wrong on the www. versus non-www. When I do a Site:NewClient.com in Google I get a total of 13 www.newclient.com url's and 20 newclient.com url's without the www. Oddly, none are dupes of the other. So, where the www.NewClient/toy-boat/ is there, the other might be non www. NewClient/toy-boat/sailing-green/ Even the contact page is in the www.NewClient/contact versus the non www of NewClient/Contact-us/ But, both pages seem to resolve to the non www. (A note here is that I originally instructed the designer to do non www to www. because the page authority was on the www.NewClient and he did opposite. With pages that are actually PDF files, if you try to use the www.NewClient/CoolGuy.pdf it comes up 404. When I check our sites, using Site:We-Build-Better.com ours return all www.We-Build-better/ url's. So, any other advice on how to insure these correct or incorrect? Oddly, we have discovered that sometimes in OSE, even with a correct canonical redirect it shows one without authority and the other with....we have contacted support. Come on mozzers, hook a brother up!0 -
What will happen after I 301 this domain?
A while back I created a new website. Somehow my "scratch" copies of the site got indexed even though I didn't have links built to them. (In the future I will use noindex tags when I am playing around with designing). Now, I have three versions of the site online...let's call them TheRealSite.com and Practice1.com and Practice2.com. Practice1.com and Practice2.com now rank #1 for their main keyword. (It's a relatively uncompetitive niche). TheRealSite.com is somewhere lower than page 20 despite having an exact keyword match domain name. I'm assuming that Google considered it duplicate content as it is the exact same thing as Practice1 and 2. I had considered simply removing Practice1 and 2 from the server, but I was worried that if I did that, I would lose my #1 rankings if TheRealSite didn't recover. So, what I've done is 301 redirect Practice1 and Practice2 to TheRealSite. I'm guessing that over time TheRealSite will come back to #1 and then I can just remove the files from Practice1 and Practice2. Is this the best way to handle this situation?
Intermediate & Advanced SEO | | MarieHaynes1