Forum Moderators: phranque

Message Too Old, No Replies

Redirecting a dynamic URL

         

Scooter24

9:44 pm on Apr 24, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



I need to redirect from a url like
www.site.com/galleries/Malaysia/Rest/img.php?pic=7

to

www.site.com/galleries/Malaysia/Ipoh/img.php?pic=4

for instance.

I placed a .htaccess file in the www.site.com/galleries/Malaysia/Rest/ directory containing this line:

redirect 301 /galleries/Malaysia/Rest/img.php?pic=7 [site.com...]

and it didn't work. But for instance

redirect 301 /galleries/Malaysia/Rest/imagehtm/image7.htm [site.com...]

works and redirects from
[site.com...]
to
[site.com...]

Now, I checked and it appears that you have to encode somehow the url-path part:
[httpd.apache.org...]

I tried to url-encode /galleries/Malaysia/Rest/img.php?pic=7 obtaining

%2Fgalleries%2FMalaysia%2FRest%2Fimg.php%3Fpic%3D7

but even this didn't work. What can I do?

jdMorgan

10:48 pm on Apr 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Redirect can't handle query-strings in the request. You'll have to use mod_rewrite.

This should work in your root directory -- above "/galleries":


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^pic=7$
RewriteRule ^galleries/Malaysia/Rest/img\.php$ http://www.site.com/galleries/Malaysia/Ipoh/img.php?pic=4 [R=301,L]

If you put the code in your "/galleries/Malaysia/Rest" directory, then it would be:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^pic=7$
RewriteRule ^img\.php$ http://www.site.com/galleries/Malaysia/Ipoh/img.php?pic=4 [R=301,L]

Jim