Redirect chains from switch to HTTPS
-
Hi,
We have a client who recently switched their site to https://
The rule to force redirect non-secure URLs to https is in their .htaccess file:
RewriteEngine on
if non-SSL and one of these, redirect to SSL
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://www.clientdomain.com/$1 [R=301,L]However, they also have simple redirects below this rule that redirect one page to another, such as:
Redirect 301 /old.php https://www.clientdomain.com/new.php
This is causing redirect chains like this:
(A) http://www.clientdomain.com/old.php > (B) https://www.clientdomain.com/old.php > (C) https://www.clientdomain.com/new.php
Is there any way to rewrite the rules in .htaccess to get rid of these redirect chains? So that URL A goes directly to URL C?
Thank you!
-
Hi,
We are still waiting for the developer to make the change. I will certainly post the answer when we know for sure!
Thanks
-
Hi was this ever resolved as this would help many people?
-
Thank you!! Just sent it
-
Yes - of course. Happy to take a look.
-
Hi Will,
That is correct - the developer told me that's exactly what he did. Could I send you a screenshot of the actual .htaccess file in a private message?
Thank you!
-
Hi Lori,
On closer inspection, I think that only the rewriterule should have the [L] flag and that placing the specific Redirect at the top of the file should work fine without chained redirects as the other commenters suggested. I tested that here: http://htaccess.mwl.be/ and it appears to work fine using the following .htaccess - can you confirm with your developer that this is what they were trying?:
Redirect 301 /old.php https://www.clientdomain.com/new.php
RewriteEngine on
if non-SSL and one of these, redirect to SSL
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://www.clientdomain.com/$1 [R=301,L] -
Thank you Will! Just one question, so if it's a simple redirect from one page to another, it would look like this? Or is adding [R=301,L] only for those that start with RewriteRule?
Redirect 301 /Bamboo https://www.fauxpanels.com/style-wood.php [R=301,L]
-
Hi Lori. The solution the other commenters have suggested is definitely the way to do this - so it sounds like it needs more debugging. I suspect it's to do with the [L] option being needed on the specific redirect once it's moved above the general http-->https redirect. This stops other redirects below it firing, if I remember correctly.
If that doesn't work, do you want to share back here the specific different htaccess files the developer has tried?
-
So the developer got back to me and said he had tried that but the redirect chain still occurred. Any other ideas?
-
So the developer got back to me and said he had tried that but the redirect chain still occurred. Any other ideas?
-
The easy solution (and recommended best practice) is to put the specific individual redirects above the HTTPS redirect in the htaccess file. Just make certain the legacy individual redirects point to the correct HTTPS version to start with.
It's standard procedure to have an htaccess file list the most specifically targeted rules first, gradually moving to the more general.
Hope that helps?
Paul
-
Thank you! Will try and let you know
-
I guess you could probably do this by checking the https rule at last. So if it is old.php, the first thing you do is redirect to the new.php but already on the https. So all your static redirects will automatically go to https with one redirect while the other will always reach the last rule and go to the secure versions. Let me know if this helps.
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
-
HTTP to HTTPS Question
Hello, I have a question regarding SSL Certificates I think I know the answer to but wanted to make sure. One of our clients’ site uses http for their pages but when they started creating Registration forms they created a full duplicate site on https (so now there are two versions of all of the pages). I know due to duplicate concerns this could be an issue and needs to resolved (as well as the pros and cons of both) but if they are already set up with https does it make sense to just move everything there or in some instances would it pay to keep some pages http (using canonical tags, redirects, htccess…etc)? – Most of the information I found related to making the decision prior to having both or describing the process but I couldn’t find anything that specifically related to if both are already present. I thought that the best approach because everything’s already set up is to just move everything over to the more secure one but was curious if anybody had any insight? Thank you in advance.
Intermediate & Advanced SEO | | Ben-R0 -
Upper to Lower Case and Endless Redirects
I have a site that first got indexed about a year ago for several months. I shut it down and opened it up again about 5 months ago. 2 months ago I discovered that the upper case in the pages: www.site.com/some-detail/Bizname/product was a no-no. There are no backlinks to these pages yet, so for search engines I put in 301 redirects to the lower case version thinking after a few weeks Bing and Google would figure it out and no longer try to crawl them. FYI there are thousands of these pages, and they are dynamically created. Well, 2 months later google is still crawling the upper case urls even though it appears that only the lower case are in the index (from when I do a site:www.site.com/some-detail ) search. Bing is also crawling the upper case although I'm not seeing any of the upper case pages and only a small percentage of the lower case ones show using a site:www.site.com/details.... command Assuming there are no backlinks will they eventually stop crawling those uppercase pages? If not, again assuming there are no backlinks, should I 410 the upper case pages, or will that remove any credit I am getting for the page having existed for over a year prior to changing the upper to lower?
Intermediate & Advanced SEO | | friendoffood0 -
Multi Language Redirect Issues
Hello everyone, this is my first post and as so let me first say, Thank you! The SEO Moz community and SeoMozPro have been giving a great help in making my workflow simpler and richer. Lately I've been reading and learning a lot about indexation, in the process I have been making several improvements to some websites, but there is one particular that I am not able to understand. I am writing this post to ask for your help on an issue related to this website: www.dengun.com We are a Web Agency based in Portugal and most our clients are from Portugal. We have an English version and a Portuguese version of the website. It is setup like this: www.dengun.com/en www.dengun.com/pt When the user hits www.dengun.com it redirects to /en or /pt acording to the browser language. The HTTP status code is 302, i was reading in SEOMoz that this is bad because it's not passing rank to the other pages. Will a 301 redirecting to /en and /pt according to the browsers language? What is the best solution? Thanks.
Intermediate & Advanced SEO | | PedroSaiote0 -
HT.Access Redirect Question
Quick question on the HT.Access / Redirects... II have a site http://www.securitysystemsfortlauderdale.org/ADT-Home-Security-Alarm-Systems/ and I am running througth SEO moz for backlinks and noticed a large descrepancy on the links on the root vs the redirect. There are more links on the root and less on the redirect. Does this affect SEO for Google or does Google follow the redirects and give credit accordingly. Thanks for your help!!! Matt
Intermediate & Advanced SEO | | joeups0 -
How can I create a redirection on IIS?
Hi, I want to know how to create a server side 301 redirection on IIS7. I found on google the below details; IIS Redirect In internet services manager, right click on the file or folder you wish to redirect Select the radio titled "a redirection to a URL". Enter the redirection page Check "The exact url entered above" and the "A permanent redirection for this resource" Click on 'Apply' But couldn't find anything like that. Can anyone help me out. thanks & regards
Intermediate & Advanced SEO | | VipinLouka780 -
.htaccess - error404 redirect within a directory?
Hi, One of my clients has a CMS website offering Health and Safety training. When the courses have been run they automatically drop off of the system which is great for the front-end of the site but this leaves pile 404 errors for the URLs. I am trying to put a .htaccess redirect in place that will redirect back to the main category for that course i/e : http://www.domain.co.uk/courses/highways/6-NRSWA/27-nrswa-operative-sept-11.html will redirect to http://www.domain.co.uk/courses/highways/6-NRSWA I have spent a looooong time hitting google for a solution but can't seem to come up with anything. If at all possible I would also like to be able to post a php variable via the redirect url so that I can display a message on the category page saying that the course is no longer available be please select a different course. i/e: http://www.domain.co.uk/courses/highways/6-NRSWA?course=not-available Any help on this would be most gratefully received.
Intermediate & Advanced SEO | | AdeLewis0 -
301 Redirect - How Long Until Recovery?
How long after one moves a page and sets up the 301s should the site take to regain its previous rankings? Context: i've ported a site to a new framework. Along the way, several high ranked pages needed to have new URLs setup, as well as the site moved from www.domain.com to simply domain.com. About 1 week after the change, the site's traffic went down 70% and has been there for about another 2 weeks. I suppose it could be something about the new framework that is causing problems though according to SEOMoz tools, the new framework is checking out pretty well. I assume the problem is reconciling all those old www inbound links with the new non-www location. It is all 301'd however ... so it should be working, but is not. So my questions are: 1. How long should it take Google to reconcile these changes and put us back to original SERP positions 2. is there something inherently problematic with switching from www to non-www?
Intermediate & Advanced SEO | | NealCabage0 -
Redirect Chains - Accept the 301 chain or link from the original page??
Hi everyone, I have a client that re-launched his site and it's gone from 100 pages to 1000 (new languages/increased product pages etc) We've used 301's to map the old site to the new database driven site. BUT the new site is creating extremely long URL's: e.g. www.example.com/example_example_example/example_example_example_example Obviously I want to change these URL's: THE PROBLEM..... I am worried about the Chain Redirects. I know two 301 redirects is okay (although it's not great), but I wonder if there is an alternative: When I've implemented the new URL structure the chain will look like this: www.oldsite.com 301 redirects to www.newsitewithdodgyurls.com which then 301 redirects to www.mynewsitewithgreaturls.com Seeing as the new site has only been live for a month, and hasn't really gained many external links, should I: 301 from the original site (www.oldsite.com) straight to the new site (www.mynewsitewithgreaturls.com)? If so, what would I do with the pages that I have not redirected? Let them 404? OR Leave the 301 chain in place? Your advice, and any other suggestions would be much appreciated Thanks
Intermediate & Advanced SEO | | jamesjackson0