Forum Moderators: phranque

Message Too Old, No Replies

301 redirect according to query string

301 redirect query string wildcard

         

gondwanan

4:53 am on May 1, 2008 (gmt 0)

10+ Year Member



I have moved my site from Windows to Linux. I now gte a lot of 404 errors because I had about 1000 pages of the format /directory.asp?id=1234

The new site has a very similar structure but it is of course /company.php?id=1234

Can someone tell me what I need to put in my .htaccess to redirect according the the query string?

Redirect 301 /directory.asp?id=*.* /content/company.php?id=*.%

Is soemthing like that possible?

the_nerd

10:50 am on May 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You won't be able to do it in a rewrite rule because the query string is not used in the rules of mod rewrite (as opposed to isapi rewrite on Windows Boxes)

You'll probably have to do the matching in den RewriteCond line, testing against %{request_uri} or something like that. You then can reference the matched string from the RewriteCond line with %N instead of $N in the RewriteRule line.

If you want to add new Url parameters but keep the exiosting ones as welln then use the [QSA] (query string append) flag.
I never tried it, but maybe this puts you in the right direction.

jdMorgan

6:02 pm on May 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You won't be able to use mod_alias directives such as Redirect, but you can use mod_rewrite's RewriteCond and Rewrite rule directives to accomplish your goal. See the Apache mod_rewrite documentation for details on those two directives.

Also, see this recent thread [webmasterworld.com].

Jim

gondwanan

8:27 pm on May 1, 2008 (gmt 0)

10+ Year Member



I've fixed it with this:

RewriteRule ^directory_display.asp$ http://www.example.co.nz/content/company [R=301,L]

e.g.

http://www.example.co.nz/directory_display.asp?i=3478

http://www.example.co.nz/directory_display.asp?i=3471

[edited by: jdMorgan at 1:09 am (utc) on May 2, 2008]
[edit reason] example.com [/edit]