Forum Moderators: phranque

Message Too Old, No Replies

htacess question

         

madk

4:44 pm on Sep 2, 2008 (gmt 0)

10+ Year Member



I am trying to redirect a dynamic url to it's new home at /wordpress. I came up with the following code which work...but also redirects any other url that contains info_id=1*.

RewriteCond %{QUERY_STRING} info_id=1 [NC]
RewriteRule ^infopages.php$ http://www.example.com/blog? [R=301,L]

I'm sure it is a minor change but I can't come up with anything that'll force it only to redirect the one url.

Any suggestions?

jdMorgan

6:18 pm on Sep 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To be clear, the URL is "example.com/infopages.php". Query strings are not part of URLs, they are data attached to a URL to be passed to the resource located at that URL.

Your code, as written above, will redirect the single URL infopages.php to /blog, but only if the query string attached to that URL *contains* info_id=1.

As currently written, the pattern will match regardless of whether this name/value in the query string is preceded by any number of any characters and/or followed by any number of any characters. So, either you need to anchor the pattern to force and exact match, meaning that the redirect will not happen if any other name/value pairs are present in the query, or you need to delimit it properly to prevent --for example-- a match on the query "newinf_id=11". This query would match your current unanchored pattern.

So, you'd need to use a pattern like


RewriteCond %{QUERY_STRING} &?info_id=1&?

to stop that. Here, we say that if a character precedes "info" or follows "id=1" it must be an ampersand.

Jim