Warning about a 302 redirect
-
Hello everyone,
I'm testing the pro software and recently I installed an SSL Certificate on one of the websites I'm monitoring, I put in place an .htaccess directive to force all traffic to the secure version of the site (https) and I noticed how this raised a warning because my directive is forcing the traffic with a 302 redirect.
These are the lines:
_RewriteCond %{SERVER_PORT} 80 _
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
I understand that this is not good so I figured since I'm already redirecting all www to -www I can force traffic that arrives trying to use www to the secure version like so:
RewriteCond %{HTTP_HOST} !^example.com$
RewriteRule (.*) https://example.com/$1 [R=301,L]
But this is not 100% effective because if someone visits the site directly on the -www version this person wont get redirected hence it wont be forced to see the https.
So my question is: does anybody know of an alternate way to force traffic to the secure socket using a 301 instead of a 302?
Oh boy, just by writing the question I think I may have figured it out, I'll post it anyways because (1) I could be wrong and (2) It could help someone else.
It just hit me but the directive that is forcing www to -www specifies what type of redirect to do here [R=301,L].
So to try to answer my own question before even posting it this could probably do the trick:
_RewriteCond %{SERVER_PORT} 80 _
_RewriteRule ^(.*)$ https://example.com/$1 [_R=301,R,L]
I'll be testing it out ASAP and again I'll post the question anyways just in case it doesn't work, in case someone has a good suggestion or to help someone that could be in the same situation.
If this is turns out right I will need someone to slap me in the face
-
Hi Steven,
Don't you just love that moment when you realize that you were clever enough to figure out the answer without help from anyone else?
Very nice of you to "take one for the team" by leaving the post to help others who might follow in your footsteps
Sha
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
-
HSTS Redirects
Hi Are these 307 redirects bad for SEO? They've just popped up on an audit & I haven't seen them before. I'm guessing as they're temporary they should be updated. Thanks Becky
Intermediate & Advanced SEO | | BeckyKey0 -
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
Intermediate & Advanced SEO | | roundabout
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!1 -
For URLs that require login, should our redirect be 301 or 302?
We have a login required section of our website that is being crawled and reporting as potential issues in Webmaster Tools. I'm not sure what the best solution to this is - is it to make URLs requiring a login noindex/nocrawl? Right now, we have them 302 redirecting to the login page, since it's a temporary redirect, it seems like it isn't the right solution. Is a 301 better?
Intermediate & Advanced SEO | | alecfwilson0 -
Redirecting index.html to the root
Hi, I was wondering if there is a safe way to consolidate link juice on a single version of a home page. I find incoming links to my site that link to both mysite.com/ and mysite.com/index.html. I've decided to go with mysite.com/ as my main and only URL for the site and now I'd like to transfer all link juice from mysite.com/index.html to mysite.com/
Intermediate & Advanced SEO | | romanbond
When i tried 301 redirect from index.html to the root it created an indefinite loop, of course. I know I can use a RewriteRule.., but will it transfer the juice?? Please help!5 -
How does Google treat chained 301 redirects?
I did the following two chained 301 redirects (A->B->C) Plural to Singular to New Domain A. http://domain1.com/filenames B. http://domain1.com/filename C. http://domain2.com/filename To new domain without www and then back to origining domain A. http://www.domain1.com/filename B. http://domain2.com/filename C. http://domain1.com/fifilename How much link juicy will be rediectetoto URL C in above two scenarios?
Intermediate & Advanced SEO | | Bull1350 -
Big 301 Redirect Help!
Hey guys I need a little help with setting up a big 301. Background: It's a bit of a mess as the old site is a total mess after being online for 10 years plus. It has html and php pages, and a mod rewrite to redirect old html links to the newer php version of those pages. It's now moving to a new site and as the domain name and URL structure has changed we can't use any fancy regex and have to do a page to page redirect. There are 1500 pages to redirect. However, the old site has thousands of linking root domains, and some of these are to the old html pages (which currently redirect to the php pages) and some to the newer php pages. Question: My initial plan was to leave the mod rewrite and only redirect the php pages. That means 1500 individual redirects instead of 3000 if I individually redirect both the php and html pages. I'm not sure what's best to be honest. We don't really want multiple hops in the redirect (html>php>new site), but surely 1500 redirects is better than 3000! Does anyone have any advice on which option may be best, or even a better option? Thanks 🙂
Intermediate & Advanced SEO | | HarveyP0 -
New Site Structure and 404s. Should I redirect everything?
Hi fellow Mozzers, I've recently re-released a site and also took the opportunity to change/clean up the URL structure. As a result of this Google is starting to report many 404s such as below; blog/tag/get-fit/ blog/tag/top-presents/ Most of these 404 errors are from tag or category pages which simply don't exist any more (because they were unnecessary, crap or irrelevant). Although there's also a few posts I've removed. My question is whether it's worth redirecting all these tags and pages to the root directory of the site's new blog (as there isn't really a new page which is similar or appropriate) or just to leave them as 404 errors. Bearing in mind; They don't really rank for anything There's little if any links pointing to these pages Thanks.
Intermediate & Advanced SEO | | PeterAlexLeigh0 -
Changing a parent category and 301 redirecting
I have a set of three pages that are subpages of a parent. The structure is as follows: mysite.com/directory/personal-widgets mysite.com/directory/commercial-widgets mysite.com/directory/widgets-services The partent page name "directory" really isn't working for where I want these pages to evolve. So I want to change it to "guides" In a world without worrying about google, I would simply change the parent page to guides, so they look like this, and be done with it: mysite.com/guides/personal-widgets But, the obvious problem is that I have external links to the page now. And the pages have a nice PR. And they also have Facebook page Likes and I don't know if I'll lose those. I know that if I should do this I should redirect the pages to the new pages of course. My question is: Will redirecting the old URL to the new URL with a 301 cause anything negative to happen that I might not be expecting? Does Google dislike Redirects for any reason, or understand they are sometimes necessary?
Intermediate & Advanced SEO | | bizzer0