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.
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
-
Domain Level Redirects - HTTP and HTTPS
About 2 years ago (well before I started with the company), we did an http=>https migration. It was not done correctly. The http=>https redirect was never inserted into the .htaccess file. In essence, we have 2 websites. According to Google search console, we have 19,000 HTTP URLs indexed and 9,500 HTTPS URLs indexed. I've done a larger scale http=>https migration (60,000 SKUs), and our rankings dropped significantly for 6-8 weeks. We did this the right way, using sitemaps, and http and https GSC properties. Google came out recently and said that this type of rankings drop is normal for large sites. I need to set the appropriate expectations for management. Questions: How badly is the domain split affecting our rankings, if at all? Our rankings aren't bad, but I believe we are underperforming our backlink profile. Can we expect a net rankings gain when the smoke clears? There are a number of other technical SEO issues going on as well. How badly will our rankings drop (temporarily) and for how long when we add the redirect to the .htaccess file? Is there a way to mitigate the rankings impact? For example, only submitting partial sitemaps to our GSC http property? Has anyone gone through this before?
Intermediate & Advanced SEO | | Satans_Apprentice0 -
Unintentional wildcard 301 Redirect?
I have migrated a client's site to a new domain. I used Yoast tools to add 301 redirects for all active site pages from old domain to new domain in the .htacces files as neither the client nor I have access to hosting server via FTP (long story). Redirects are working as I intended, and we didn't lose too much in our rankings. Unfortunately, as soon as I saved the .htaccess file in Yoast, old-domain.net/wp-admin began redirecting to new-domain.net/wp-admin. I can no longer login to the wordpress site on the old domain. I did not enter a redirect for /wp-admin. Any thoughts on how this is happening or if there is some other way to get back in? Without server access, I'm pretty stumped. Thanks!
Intermediate & Advanced SEO | | c_estep_tcbguy0 -
Blog subdomain not redirecting
Over the last few weeks I have been focused on fixing high and medium priority issues, as reported by the Moz crawler, after a recent transition to WordPress. I've made great progress, getting the high priority issues down from several hundred (various reasons, but many duplicates for things like non-www and www versions) to just five last week. And then there's this weeks report. For reasons I can't fathom, I am suddenly getting hundreds of duplicate content pages of the form http://blog.<domain>.com</domain> (being duplicates with the http://www.<domain>.com</domain> versions). I'm really unclear on why these suddenly appeared. I host my own WordPress site ie WordPress.org stuff. In Options / General everything refers to http://www.<domain>.com</domain> and has done for a number of weeks. I have no idea why the blog versions of the pages have suddenly appeared. FWIW, the non-www version of my pages still redirect to the www version, as I would expect. I'm obviously pretty concerned by this so any pointers greatly appreciated. Thanks. Mark
Intermediate & Advanced SEO | | MarkWill0 -
Duplicate Errors from Wordpress login redirects
I've some Duplicate issues showing up in Moz Analytics which are due to a Q&A plugin being used on a Wordpress website which prompts the user to login. There's a number of links looking like the one shown below, which lead to the login page: www.website.com/wp-login.php?redirect_to=http%3A%2F%2Fwww.website.com%question%2.... What's the best way to deal with this? -- extra info: this is only showing up in Moz Analytics. Google Webmaster Tools reports no duplicates.. I'm guessing this is maybe down to the 'redirect_to' parameter being effective in grouping the URLs for Googlebot. currently the wplogin and consequent redirects are 'noindex, follow' - I cannot see where this is being generated from in wp-login.php to change this to nofollow (if this will solve it).
Intermediate & Advanced SEO | | GregDixson0 -
301 Redirect of subdomain?
Fellow Mozzers, I'm having a hard time wrapping my brain around a redirect issue and thought it was worth posing the question to the Moz community. I did a search first but couldn't find the exact answer I was looking for. How does a 301 redirect work when you redirect a sub domain example.homepage.com to www.homepage.com but you keep the sub directories of example.homepage.com/page-1 active and are trying to rank them? I'm dealing with a current project where this is happening and this doesn't make sense to me, to redirect the subdomain if you're also trying to rank/create search traffic for pages, sub directories on example.homepage.com. This also get's into the debate of if a sub domain site is viewed as it's own website and therefore has to rank itself. If this is true, it seems like we're kind of killing the authority of the site by redirecting it. Additionally, www.homepage.com has a much stronger link profile than example.homepage.com I hope this makes sense. Any thoughts are appreciated. Thanks for your time.
Intermediate & Advanced SEO | | SMG-Texas0 -
How to 301 redirect all URLs with /? in?
I want to redirect all URLs that have /? in it. Indexed in Google is a bunch of urls lik: mysite.com/?674764 mysite.com/?rtf8y78 I want all these URLs to be redirected to my home page. Any ideas?
Intermediate & Advanced SEO | | JohnPeters0 -
How long is it safe to use a 302 redirect?
Hi All, Lets assume there is site A and site B, both sites are live on the internet today as standalone businesses, but they sell very similar products. Site B has built up some link equity and will eventually become the domain for site A due to an organisational re-brand. For the time being however site A will remain, but site B needs to disappear temporarily, but not lose the link equity which has been built up against it. My current thinking is to 302 redirect site B to site A such that users and search bots accessing site B will be redirected to site A whilst leaving the link equity that exists against site B fully intact and allowing us to continue to grow it should we wish to. The question is, does anybody have a view on how long it is safe to use a 302 temporary redirect for? i.e., is 8-10 months to long. Thanks, Ben
Intermediate & Advanced SEO | | BenRush0 -
Redirects/Forwarding
I have two niche e-commerce sites. One is a PR3 with 3K pages indexed, the other is PR0 with 5K pages indexed. Each site has a blog that has been updated regularly. They both rank well for some fairly competitive keywords and some good links pointing to them. I also have a main site that is PR3. I am thinking of closing down the sites because they are not generating enough revenue, here are my questions: What is the best way to get the most SEO value from these sites? Do I just do a redirect to the main site? Should I keep the sites and use canonical URLs to the main site? Should I keep the domain as a wordpress blog and point links to the main site? What should I do with the blogs? They are on sub-domains, neither has pagerank. Thanks
Intermediate & Advanced SEO | | inhouseseo0