Forum Moderators: phranque

Message Too Old, No Replies

Not sure RedirectMatch is the best way to do this.

         

spadilla

6:57 pm on Oct 27, 2009 (gmt 0)

10+ Year Member



Hello - I am trying to redirect old dynamic URLs from a php script to new ones. There is only a minor change in the new URL structure.

The old URLs look like:
real-estate?view=property&id=405

And I need to 301 them to:

real-estate?view=properties&id=405

Obviously there are hundreds of property IDs and I would like if they forwarded to the new "correct" version of the URL. I contacted the developer and he told me to do this:

RedirectMatch 301 ^/real-estate?view=property&id=(.*)$ [yoursite.com...]

However that doesn't work at all. I've tried fiddling with other options, but I'm afraid I'm too much of a noob to figure this one out. Any help would be greatly appreciated!

jdMorgan

7:56 pm on Oct 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That won't work, because neither mod_alias' RedirecMatch nor mod_rewrite's RewriteRule directives can 'see' query strings.

You'll need to use mod_rewrite. If you currently have no working mod_rewrite code, you'll need either all of these lines or only the last three -- I can't tell, and you'll have test to find out.

If you do currently have other working mod_rewrite rules, you'll need only the last two, and this new rule should be placed before any more-general external redirect rules (e.g. domain canonicalization), and before all internal rewrite rules:


Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{QUERY_STRING} ^view=property&id=(.+)$
RewriteRule ^real-estate$ http://www.example.com/real-estate?view=properties&id=%1 [R=301,L]

I assume that you'll put this code in your Web root .htaccess file. If you intend to put it elsewhere, then it will need to be tweaked.

Jim

spadilla

8:22 pm on Oct 27, 2009 (gmt 0)

10+ Year Member



Let me just say that you ROCK! That fixed it and it works perfectly now. Thanks SO much!