Forum Moderators: coopster

Message Too Old, No Replies

.htaccess code to fix 300 and 302 redirects

Getting 300 and 302 redirects on variations of index.*

         

feralreason

9:58 pm on Jan 5, 2012 (gmt 0)

10+ Year Member



I'm testing a newly uploaded site on [ragepank.com...] and I'm getting a number of 300 and 302 redirects. All of these are variations on the following:

[b2wflooring.com...] returns a HTTP/1.1 300 Multiple Choices response
[b2wflooring.com...] returns a HTTP/1.1 300 Multiple Choices response
[b2wflooring.com...] returns a 302 (temporary) redirect
[b2wflooring.com...] returns a 302 (temporary) redirect

Does anyone know what .htaccess code I use to point all these to [b2wflooring.com...] ?

I'm fairly new at using .htaccess so any help would be appreciated !

g1smd

10:02 pm on Jan 5, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You already have some code (somewhere on the site) that produces a 302 redirect.

You need to alter that code not add more code otherwise you will have a multiple step redirection chain, or worse, an infinite loop.

You should not redirect to a named index file. You should redirect to strip the name and the new URL should end in a trailing slash.

Use example.com in this forum to stop the URL auto-linking process.

By linking to your own site, the URLs you have quoted will be requested by Googlebot forever.

feralreason

10:30 pm on Jan 5, 2012 (gmt 0)

10+ Year Member



g1smd -- Thanks much ! The code I have in the .htaccess file at present is the following:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.b2wflooring\.com
RewriteRule (.*) [b2wflooring.com...] [R=301,L]
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ [b2wflooring.com...] [R=301,L]

ErrorDocument 404 [b2wflooring.com...]

Could any of this be producing the 302 error ?

g1smd

10:35 pm on Jan 5, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Alter that code to have the index redirects first. The currect order produces a double redirect for some requests. You do not want that.

Alter the index redirect code to redirect requests other than index.php and make sure it works for folder and root.

This code should appear at the start of the code and appear only once:
RewriteEngine on
Options +FollowSymLinks

In most cases .* is not the pattern to use here. See previous threads in the Apache forum for what to replace it with. It's been discussed many times.

Your ErrorDocument directive will never produce a 404 status. It will produce a 302 status because you included a domain name. The Apache manual explicitly warns to not do this.

Your non-canonical redirect doesn't redirect www requests with a port number. Use
!^(www\.example\.com)?$
as the pattern. The anchoring makes all the difference.

Make all of the above changes. This might not fix all of your problems but the code you have now is causing a lot of other problems, or will cause new problems when you clear up your original problem.

[edited by: g1smd at 10:45 pm (utc) on Jan 5, 2012]

feralreason

10:43 pm on Jan 5, 2012 (gmt 0)

10+ Year Member



g1smd, Thanks much.

Rearranged like this, but still getting the same results. Did I do something wrong ?

RewriteEngine on
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ [b2wflooring.com...] [R=301,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.b2wflooring\.com
RewriteRule (.*) [b2wflooring.com...] [R=301,L]

ErrorDocument 404 [b2wflooring.com...]

Really appreciate your help.

g1smd

10:46 pm on Jan 5, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Check previous post again, you have at least 15 more changes to make to your code.

feralreason

10:50 pm on Jan 5, 2012 (gmt 0)

10+ Year Member



Of course ! My apologies. I'll work through it.

Thanks so much.