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
-
Mass 301 redirect in htaccess
I use ScreamingFrog to generate sitemaps for my Magento 2 multistore, but I recently noticed two issues. Each category/page has two URLs. One with / and the end and one without. Every product has two URLs. One with /product-name and the other /shop/product-name. The URLs are canonicalised, but this is still a problem and I'm not sure exactly how to execute this in the htaccess file. So I need to: Remove all URLs without the / at the end and redirect them all to the URL with / at the end. Or vice versa. 301 redirect every single product (there are over 400) from shop/product-name to /product-name. How do I do this en mass in the htaccess file?
Intermediate & Advanced SEO | | moon-boots0 -
What are the best practices with website redesign & redirects?
I have a website that is not very pretty but has great rankings. I want to redesign the website and loose as little rankings as possible and still clean up the navigation. What are the best practices? Thanks in advance.
Intermediate & Advanced SEO | | JHSpecialty0 -
Php 301 redirect
Hi I am migrating an old wordpress site to a custom PHP site and the URL profiles will be different, so want to retain all link profiles and more importantly if a user visits the old urls via search then they are seamlessly transferred to the new equivalent page For example www.domain.com/about-us is going to need to redirect to www.domain.com/aboutus.php www.domain.com/furniture is going to need to redirect to www.domain.com/furniture-collections.php etc What is the best way of achieving this apart from .htaccess as not 100% confident of doing this. Could it be done via PHP or using meta tags?
Intermediate & Advanced SEO | | ocelot0 -
Questions about 301 Redirects
I have about 10 - 15 URLs that are redirecting to http://www.domainname.comwww.domainname.com/. (which is an invalid URL)The website is on a Joomla platform. Does anyone know how I can fix this? I can't figure out where the problem is coming from.
Intermediate & Advanced SEO | | JohnParker27920 -
301 redirect for duplicate content
Hey, I have just started working on a site which is a video based city guide, with promotional videos for restaurants, bars, activities,etc. The first thing that I have noticed is that every video on the site has two possible urls:- http://www.domain.com/venue.php?url=rosemarino
Intermediate & Advanced SEO | | AdeLewis
http://www.domain.com/venue/rosemarino I know that I can write a .htaccess line to redirect one to the other:- redirect 301 /venue.php?url=rosemarino http://www.domain.com/venue/rosemarino but this would involve creating a .htaccess line for every video on the site and new videos that get added may get missed. Does anyone know a way of creating a rule to rewrite these urls? Any help would be most gratefully received. Thanks. Ade.0 -
301 Redirects After Company Acquisition
We recently acquired a company, and now we are going to redirect all of the pages on their site to their respective pages on our site. Do we need to keep the original pages on their site active? For how long? Ideally, we would like to redirect everything and remove the old site entirely so we don't have to pay to keep hosting it. Is this possible? Thanks!
Intermediate & Advanced SEO | | pbhatt1 -
Cookies and redirects - what are the negative effects?
I am advising a client who wants to streamline their online customers experience through the use of cookies. The first time someone visits mysite.com, they will visit the normal index page, and on that page will be asked to identify themselves as a Personal or Business customer - and taken through to a relevant page. This will result in a cookie being added. The next time they come back to mysite.com, the cookie will automatically direct them from the index page to mysite.com/personal/ or mysite.com/business/. My question is, what are the SEO implications of this, especially given the fact the index page is their primary landing page for almost all organic traffic? Bots I realise that googlebot etc do not store cookies, so this should result in no change from the bots perspective (i.e. no redirect) but is it that simple? In effect we'll be showing the bot one thing and second time + visitors something else. Is this not effectively cloaking? All advice gratefully received!
Intermediate & Advanced SEO | | seomasters0 -
Redirecting Powerful Domains
What do you do if you have a client that never implemented a 301 redirect on their domain? For example here are the OSE stats for the URLs; http://url.com PA: 48 DA: 50 LRD: 65 TL: 1,084 FB: 178 FB: 14 T:5 http://www.url.com PA: 51 DA: 50 LRD: 165 TL: 2,271 FB: 178 FB: 14 T:5 G+1:3 My first instincts are to redirect the first one to the second one, but is it too late for that? Will that screw up all of their established stats? Any input or examples of past experiences with this would be great.
Intermediate & Advanced SEO | | MichaelWeisbaum0