Forum Moderators: phranque

Message Too Old, No Replies

301 Redirect Query string to a static page

         

domble

12:33 pm on Feb 23, 2009 (gmt 0)

10+ Year Member



I need to redirect a list of URLs.

The old one's are index2.php + lots of query strings.

I just want to specifiy the string and specify the page.

For example -

index2.php?page=addressable
REDIRECT TO
addressable.html

How would I do this ?

The 'redirect to' page doesn't need to be dynamic based on the string, I'm happy to specify each one individually.

Any help would be greatly appreciated.

g1smd

1:23 pm on Feb 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What code have you tried so far?

Similar questions to this are asked at least several times each week, and so there are already several thousand posts, stretching back a decade, with examples to get you started.

domble

1:37 pm on Feb 23, 2009 (gmt 0)

10+ Year Member



I understand that there are many examples. However after looking at them they are either; redirect one page to another or redirect a query string request to page name matching string. I just want to build a list.

E.G.

redirect 301 /portal.php [domain.com...]
redirect 301 /index2.php?page=contact [domain.com...]

The first line works no problem but the second line doesn't. The examples I have found re-write the query string request to the page name contact.htm or html but I want to manually specify the redirect ?page=contact to contact-us.html or maybe ?page=main to index.html. I cannot find an example of this. If I could I wouldn't of made this post.

Any help, again would be grealy appreciated.

[edited by: domble at 1:45 pm (utc) on Feb. 23, 2009]

g1smd

1:45 pm on Feb 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Those that redirect to a specific page name have a $1 in the target to specify that page name. If you omit the $1, then the rule will redirect to the fixed URL you specify as the target.

Your second rule does not work because Redirect cannot see the query string value. You'll need to use RewriteRule instead, with a RewriteCond to test the QUERY_STRING value.

Be aware that if you use RewriteRule you should not use Redirect or RedirectMatch anywhere in the same .htaccess file. That is, you should use RewriteRule for all of your redirects and rewrites.

Don't specify index file filenames as the target URL of any redirect. Use the bare domain name with trailing slash, or else domain name, plus folder name with trailing slash.

npimpfellow

5:47 am on Mar 10, 2009 (gmt 0)

10+ Year Member



I want to set my page so that

?query=1
redirects to a site
?query=2
redirects to a different site
?query=3
redirects to a different site

and so on

please help!

g1smd

9:18 am on Mar 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This sort of code is posted almost every day - so there are thousands of similar examples here.

Post your best effort code and explain clearly in what way it is not working.