Forum Moderators: phranque

Message Too Old, No Replies

A simple mod rewrite - need help bad

redirects all arrive at same place = wrong

         

promoking

1:39 am on Jan 9, 2011 (gmt 0)

10+ Year Member



This should be simple (I think) but I've been pulling my hair out fulltime on this for almost 2 days now. We are moving our site to a new server/host and have updated from an old asp shopping cart to php. The plan is to use 301 to preserve as much inlinks as possible.

The 1st rule gets processed perfectly. However the 2nd returns the same result as the 1st even though it should be going to a different directory.

RewriteEngine on
RewriteBase /

RewriteCond %{QUERY_STRING} ^ID=100$ [NC]
RewriteRule samepath/samefilename\.asp TLD/thisDir/? [R=301,L]
#
RewriteCond %{QUERY_STRING} ^ID=200$ [NC]
RewriteRule samepath/samefilename\.asp TLD/differentDir/? [R=301,L]

Please PLEASE help... oh and I'm running A2.x hosted at 1and1.com

* TLD = the complete top level domain url
** If I add another cond&rule but use either a different path or different filename (or both) that works fine.

Thanks

-Brian

jdMorgan

5:03 pm on Jan 9, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For clarity, you can specify a full substitution URL path including protocol and domain by using "http://www.example.com/" or "http://example.com/" -- Neither of these will be auto-linked by this forum.

Your code looks fine except that the URL-path patterns are not properly anchored and are therefore somewhat ambiguous.

Also, be sure to delete your browser cache before testing any new server-side code. Forcing a reload is not sufficient in many cases; it is best to actually delete the cache and/or disable it entirely for testing.

Jim

promoking

7:34 pm on Jan 10, 2011 (gmt 0)

10+ Year Member



Thanks a ton!

Can you please tell me if the numerical ordering of the condition matters? EX:

RewriteCond %{QUERY_STRING} ^ID=100$ [NC]
RewriteRule samepath/samefilename\.asp http://www.example.com/thisDir/? [R=301,L]
#
RewriteCond %{QUERY_STRING} ^ID=300$ [NC]
RewriteRule samepath/samefilename\.asp http://www.example.com/differentDir/? [R=301,L]
#
RewriteCond %{QUERY_STRING} ^ID=200$ [NC]
RewriteRule samepath/samefilename\.asp http://www.example.com/differentDir3/? [R=301,L]

Will that still work or does the condition being out of order break it?

Thanks!

-Brian

jdMorgan

4:01 pm on Jan 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The order makes no difference, since you are using exact-match patterns.

However, there's no reason to use three partially-redundant rules, when this would be equivalent:

RewriteCond %{QUERY_STRING}>thisDir ^ID=100>(.+)$ [NC,OR]
RewriteCond %{QUERY_STRING}>differentDir ^ID=300>(.+)$ [NC,OR]
RewriteCond %{QUERY_STRING}>differentDir3 ^ID=200>(.+)$ [NC]
RewriteRule ^samepath/samefilename\.asp$ http://www.example.com/%1/? [R=301,L]

The ">" character has no special meaning. It is used only to demarcate the end of the required query value from the beginning of the new "dir" path to be copied into the substitution URL.

A bit 'tricky' but a lot more efficient...

Jim