Welcome to WebmasterWorld Guest from 54.162.139.105

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Issue with redirect looping

     
8:16 pm on Nov 28, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:May 29, 2007
posts:73
votes: 0


The following rewrite is resulting in an infinite loop.

Basically I want anything that goes to blog which contains letters or - for 2 directories after blog to redirect to tags using the $1.

I thought the following would work but it's not doing a good job as it results in the rewrite to be like this:

http://www.example.com/blog/tags/tags/index.html

This is not the desired effect but I assume it's doing that because it's redirecting again after the initial redirect. I tried to resolve that by checking request uri for the word tags. But that didn't resolve the problem :(

Any suggestions would be greatly appreciated.


RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/tags/
RewriteRule ^/blog/([A-z\-]*)/([A-z\-]*)/index.html$ http://www.example.com/blog/tags/$1/index.html [R=301,L]
9:53 pm on Nov 28, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14244
votes: 550


So you want the rule to work for

www.example.com/blog///indexzhtml

but only if the request wasn't for

www.example.com/tags/more-stuff-here

?

Look at that for a moment and you can start sorting out the problems.
10:14 pm on Nov 28, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:May 29, 2007
posts:73
votes: 0


I do see the problem, it's reading itself.

But how do I go about telling it that it must have tags and more stuff here?
10:42 pm on Nov 28, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:May 29, 2007
posts:73
votes: 0


OMG! I'm a putz. I figured it out thanks!


RewriteCond %{REQUEST_URI} !^/blog/tags/
RewriteRule ^blog/([A-z\-]*)/([A-z\-]*)/index.html$ http://www.example.com/blog/tags/$1/index.html [R=301,L]
11:32 pm on Nov 28, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


You MUST list the redirecting rule before the rule that rewrites.

It's a good idea to have a non-www/www canonicalisation rule after all other redirects and before the rewrite(s).

Make sure all your rules use RewriteRule syntax and NOT Redirect or RedirectMatch.

Do not redirect to a named index page. The correct URL ends with a trailing slash.