Forum Moderators: phranque

Message Too Old, No Replies

MOD ReWrite Loop

         

myutopia

11:47 am on Jun 17, 2004 (gmt 0)

10+ Year Member



I've been pulling my hair out trying to get this to work but it seems to get caught in a loop.

I want to got to www.mydomain.com/test and it to redirect me to www.mydomain.co.uk/new/testpage.jsp
and
If I go to www.mydomain.com/old/test and it to redirect me to www.mydomain.co.uk/old/oldtest/testpage.jsp

I've tried this

RewriteEngine on
RewriteCond %{HTTP_HOST}!^www\.mydomain\.co\.uk [NC]
RewriteRule ^/test [mydomain.co.uk...] [R]
RewriteRule ^/old/test [mydomain.co.uk...] [R]

but it just seems to loop as though the rule for /old/test is clashing with the rule for /test

Any ideas

bsterz

12:39 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



I'll defer to the masters on the issue with the rewrites, but what has helped me immensely is the following in an httpd.conf file:

RewriteLog /var/log/httpd/rewrite.log
RewriteLogLevel 9

Fascinating to view..

9 is the highest amount if info available, while 0 is the lowest. Use this for debugging only as there are performance implications to logging rewrites.

myutopia

2:03 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



I looked in the log and could see it looping.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.mydomain.co.uk$ [NC]
RewriteCond %{REQUEST_URI} ^/test$ [NC]
RewriteCond %{REQUEST_URI} ^/old/test$ [NC]
RewriteRule ^/test /new/test/testpage.jsp [R]
RewriteRule ^/old/test /old/oldtest/testpage.jsp [R]

Changed it to this and this seemed to sort it.
Probably not the most clever way of doing it but atleast it now works.

jdMorgan

3:27 pm on Jun 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



myutopia,

Welcome to WebmasterWorld [webmasterworld.com]!

Characters which have special meanings in regular expressions should be escaped by preceding them with a "\", as show for your domain name below.


RewriteCond %{HTTP_HOST} ^www\.mydomain\.co\.uk$ [NC]

Be aware that RewriteConds apply only to the first RewriteRule that follows them, and that mod_rewrite will continue rewriting as long as it finds matching RewriteRules. If you do not wish further rules to be applied after a match is found, use the [L] flag.

Also, you are specifying a 302 Temporary redirect here, so search engines will not update to use the new URL. If you wish them to list your new URLs, then use [R=301].

Jim