Jump to content

Change 302 to 301 Redirect


Nortski

Recommended Posts

Hi all,

 

When I do a 301 redirect check using the free tool at http://www.ragepank.com/redirect-check/, it shows that my index page, and all variants of it, are 302 redirected.

 

How do I change this situation so they are all 301 redirecting to my desired URL eg http://www.mysite.co.uk/

 

I would normally add

 

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mysite\.co\.uk
RewriteRule (.*) http://www.mysite.co.uk/$1 [R=301,L]

 

to the .htaccess file, but the current one has no references to any 302 redirects.  This begs the question, how and where are the 302's coming from?

 

Thanks in advance.

Nortski.

 

 

Link to comment
Share on other sites

Hi, I have a similar problem using the rangepank tool. I also changed the htaccess file

 

but rangepank shows me the following, but my selected domain is with www:

 

Link to comment
Share on other sites

I think this is the problem I'm having as well.

 

The base url of the shop I'm working on is www.(domain).com/ and works fines. However, when accessing the site using just (domain).com/, a 302 temporary redirect is performed to www.(domain).com/

 

I want this to be a 301 permanent redirect instead. Does anyone know how to make it so?

Link to comment
Share on other sites

Hi friends,

 

I have found the solution for my problem in another site, I hope this could help you. I wrote this:

 

 

RewriteCond %{HTTP_HOST} !^(.*)\.asianexoticdream\.com$ [NC]
RewriteRule ^(.*)$ http://www.asianexoticdream.com/$1 [R=301,L]

 

Just change asianexoticdream, and write your domain. 

 

After this, I used again the tool: http://www.ragepank.com/redirect-check/

and it returned 301 for www and without www.

 

I hope it could be useful for you.

Link to comment
Share on other sites

  • 2 months later...

Thanks for that snippet Syd. It worked perfectly for me. For anyone else who wants to use it, just be sure you have in your SEO and URLs section in your back office, your site must be set to use the www. version of your domain in order for the above code to work properly. it will NOT work without the www. set.

Link to comment
Share on other sites

I think the proper course of action here would be to steer clear of locking anyone into one method or the other and instead simply modify the current hooks code for setting the different http status flags so that each redirect can be set with it's own status. It will default to 302 like it should, but you will have the option to add 301 using the hooks in a custom module as an extra argument to the already existing hook arguments. This would still keep the module lightweight as adding such a feature will only take a couple lines.


BTW, the reasoning for using 302 by default is that it's usually best practice to leave permanent changes to a site that is not yours, up to the owner. Since this is not a database change, they could not easily revert 301 to a 302 if it should happen to get spidered with a 301 that happened to cause problems. It's easier to revert from a 302 than it is a 301 and that is the reason why most redirects default to 302 unless otherwise specified as such. It's almost like making a change to an entire website without first making a backup. It might work, but then again it might not. You'll always want to have the option to revert back if something goes wrong and that is what 302 designed for.


Link to comment
Share on other sites

  • 1 year later...

Also, in your .htaccess file you'll want to add your site's IP address.  Obviously replace the "yourwebsite" part with your site and replace the IP 111.111.111.111 with your sites IP.  Place this above the line "#~~start~~ Do not remove this comment..........." .

 

 

RewriteEngine on

#

## NON WWW REDIRECTION TO WWW
RewriteCond %{HTTP_HOST} ^yourwebsite.com$
RewriteRule ^(.*)$ "http\:\/\/www\.yourwebsite\.com\/$1" [R=301,L]
#
## IP REDIRECTION TO WWW
RewriteCond %{HTTP_HOST} ^111\.111\.111\.111
RewriteRule (.*) http://www.yourwebsite.com/$1 [R=301,L]
#
#

# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again

Edited by nakecorp2 (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...