Forum Moderators: phranque

Message Too Old, No Replies

Redirect 301 doesn't work

Redirect URL with long query string appended

         

cssatsc

10:56 pm on Jun 26, 2009 (gmt 0)

10+ Year Member



Can I used Redirect 301 to redirect from this non-existing URL:

[{domainname}.com...]

To another valid URL in my site?

If so, how do I do that?

I tried the simple syntax (all in one line, of course):

redirect 301 /shop/index.php?main_page=product_free_shipping_infoReallySearchcPath=2ReallySearchproducts_id=28 [{domainname}.com...]

But that doesn't work (I am still getting 404).

Other redirect statements (shorter) work fine. I suspect this has to do with the question marks in the URL?

Your help is appreciated.

g1smd

12:04 am on Jun 27, 2009 (gmt 0)

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



You need to use a RewriteRule and a RewriteCond to examine the QUERY_STRING

You can't use Redirect for this, as it cannot 'see' the query string part.

cssatsc

12:42 am on Jun 27, 2009 (gmt 0)

10+ Year Member



Thank you, g1smd. I found the following formal documentation:

[httpd.apache.org...]

Can you recommend a tutorial or a similar example that can help me get there faster?

Thanks.

jdMorgan

1:53 am on Jun 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need to use mod_rewrite, since the mod_alias directives cannot 'see' query strings. As g1smd stated, you must examine QUERY_STRING with a RewriteCond:

Options +FollowSymLinks -MultiViews
RewriteEngine on
#
RewriteCond %{QUERY_STRING} ^main_page=product_free_shipping_infoReallySearchcPath=2ReallySearchproducts_id=28$
RewriteRule ^shop/index\.php$ http://www.example.com/shop/index.php?main_page=product_free_shipping_info&cPath=2&products_id=28 [R=301,L]

Jim

cssatsc

3:00 pm on Jun 28, 2009 (gmt 0)

10+ Year Member



Jim, thank you so much! Your example helped me implement this quickly and successfully.