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
-
Rel Canonical for HTTP and HTTPS pages
My website has a login that has HTTPS pages. If the visitors doesn't log in they are given an HTTP page that is similar, but slightly different. Should I sure a Rel Canonical for these similar pages and how should that be set up? HTTP to HTTPS version or the other way around? Thank you, Joey
Intermediate & Advanced SEO | | JoeyGedgaud1 -
Multiple 301 redirects for a HTTPS URL. Good or bad?
I'm working on an ecommerce website that has a few snags and issues with it's coding. They're using https, and when you access the website through domain.com, theres a 301 redirect to http://www.domain.com and then this, in turn, redirected to https://www.domain.com. Would this have a deterimental effect or is that considered the best way to do it. Have the website redirect to http and then all http access is redirected to the https URL? Thanks
Intermediate & Advanced SEO | | jasondexter0 -
Is there anything wrong with this 301 redirect?
I'll keep this one short and sweet 🙂 Many moons ago we used to have several different methods of sorting our products and this change in sort order was achieved by having ?dispmode=list or ?dispmode=grid after the product URL. Best part of a year ago we decided to scrap this feature and 301'd all the ?dispmode URL's back to the base URL. The funny thing is that Google don't seem to have dropped a single one of the old URL's from their index and a search for site:www.refreshcartridges.co.uk dispmode returns almost 8,000 results. This isn't a massive problem but I'd have expected in the past year they'd have picked up on a couple of the 301's and would have started removing the old results. I'd hate to think we were getting any kind of penalisation for duplicate pages. I know the answer to this question is going to be 'just be patient, the old results will disappear' but just to ensure we're not missing anything stupid. I'd really appreciate it if someone could check out www.refreshcartridges.co.uk/brother-c-223.html?dispmode=list to confirm there's nothing more we could be doing to get these old results removed from the index. Many thanks
Intermediate & Advanced SEO | | ChrisHolgate0 -
Redirect gateway domain to main domain?
We have following scenario: Our main website - www.esedirect.co.uk which gets a 1800 visits a day with around half of those from organic search. It's been around since 2004. Our original website - www.ese.co.uk which gets around 30 visits a day and really is nothing more than a doorway page with links to the above site and couple of other sites that belong to the same company. This is an old domain that's had content since 1997 and has good domain authority with some good links. We are considering doing a 301 redirect from www.ese.co.co.uk to www.esedirect.co.uk to redirect the link juice. I welcome opinions to any possible negative effects this could give and how beneficial doing this will be. Thanks, Lee
Intermediate & Advanced SEO | | ese0 -
Are there any concerns moving a site to https?
I am currently having analytics issues where the non-secured (http) front end of my site is not properly communicating to the backend (https) of my site. When a user jumps between the the secured and non-secured, it will display as a bounce in GA and I get duplicate visits. GA has a work around for this but it is messy and not working. So my question is, has anyone had good/bad experiences moving a non-secured site over to the secured side? Thanks!
Intermediate & Advanced SEO | | 2comarketing0 -
Not allowing me 301 Redirect
I am trying redirect my old site to my new site, both on the same domain. For one reason or another, I am having a hard time redirecting the some of the old urls to the new site. Please let me know how I can fix this issue. Below are the following old urls that are not allowing me to redirect: <colgroup><col width="636"></colgroup>
Intermediate & Advanced SEO | | Melia
| http://www.meliacaribetropical.com/press/melia-caribe-tropical-announces-fall-promotion.html |
| http://www.meliacaribetropical.com/press/melia-international-brand-overhaul.html |
| http://www.meliacaribetropical.com/spanish/accommodations/ |
| http://www.meliacaribetropical.com/spanish/dining/ |
| http://www.meliacaribetropical.com/spanish/entertainment/ |
| http://www.meliacaribetropical.com/spanish/events/ |
| http://www.meliacaribetropical.com/spanish/flintstones/ |
| http://www.meliacaribetropical.com/spanish/gallery/ |
| http://www.meliacaribetropical.com/spanish/gallery/beach.html |
| http://www.meliacaribetropical.com/spanish/gallery/dining.html |
| http://www.meliacaribetropical.com/spanish/gallery/pools.html |
| http://www.meliacaribetropical.com/spanish/press/ |
| http://www.meliacaribetropical.com/spanish/press/melia-caribe-tropical-announces-fall-promotion.html |
| http://www.meliacaribetropical.com/spanish/press/melia-international-brand-overhaul.html |0 -
.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 -
Switching to masked affiliate links
Hi there, I run a content affiliate website where I introduce products in articles and then link to merchants where the user can buy the respective product. Currently I am using regular affiliate links here with the "nofollow" attribute. With growing size of the site, I would like to switch to masked affiliate links, so instead of a link like "jdoqocy.com/click-123" I want to use "mydomain.com/recommend/123". My question here is: When switching to masked affiliate links, does it makes sense to also convert all the older unmasked affiliate links? If yes, what would be the best way to do that - Convert all old links at once or convert them over time (e.g. over a few month)? Currently about 2/3 of my site's outbound links are unmasked, external affiliate links. So I am afraid that changing this relatively large share of links from unmasked external affiliate links to masked links doenst look natural at all... Thank you for your advice!
Intermediate & Advanced SEO | | FabRag0