Forum Moderators: phranque

Message Too Old, No Replies

Simple query string rewrite?

         

travelvice

6:04 am on Feb 28, 2008 (gmt 0)

10+ Year Member



I have a page at http://example.com/archive/ which I would like to redirect (permanently) to [subdomain.example.com...]

BUT, there are many incoming hyperlinks that point to this page with URL's like this:

http://example.com/archive/
http://example.com/archive/?by=date
http://example.com/archive/?by=country
http://example.com/archive/?by=country#England

I guess I should note that there are other URL's further down the path that feed off the /archive/ directory... those should stay put.

I was trying something along these lines, with no success:

rewriteEngine On
RewriteCond %{QUERY_STRING} ^by=(.*)$
rewriteRule ^/archive/index.php$ [subdomain.example.com...] [R=301,L]

Thoughts?

travelvice

6:19 am on Feb 28, 2008 (gmt 0)

10+ Year Member



I think I've nearly got it...

rewriteEngine On
rewriteCond %{HTTP_HOST} !^example\.com/archive/index.php
rewriteCond %{QUERY_STRING} ^(.*)$
rewriteRule ^(.*)$ [subdomain.example.com...] [R=301,L]

Only problem is that it's also doing items (URLs) deeper into the archive directory as well...

jdMorgan

6:36 am on Feb 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're over-complicating it a bit... :)

RewriteEngine on
RewriteRule ^archive/$ http://subdomain.example.com/ [R=301,L]

Query strings are passed through mod_rewrite unchanged by default.

Jim

travelvice

7:01 am on Feb 28, 2008 (gmt 0)

10+ Year Member



Hi Jim,

Oddly, this seems to do nothing at all... no sign of any change. ... though the code previous changed everything just fine, with the exception that it was also impacting the URLs below the archive level.

Is there a way to add an ignore clause into that one? I'll take over-complicated over non-functioning. :)

//craig

travelvice

7:25 am on Feb 28, 2008 (gmt 0)

10+ Year Member



ahhh -- that was the problem. I moved the rule to the root of the domain, and not in the archive directory.

Thanks Jim!