Forum Moderators: coopster

Message Too Old, No Replies

Redirecting a Query String using PHP

How do I redirect a dynamic link to use new files?

         

flagtothefloor

7:16 am on Dec 20, 2006 (gmt 0)

10+ Year Member



Hello- this should be pretty easy, I'm just not a PHP expert.

I built a new site, but the browsers and other websites link to my product pages using a query string link with old filenames. I need to redirect the queries to use the new filenames.

How would I create this redirect?

Example
----------

Old Site:

[domain.com...]

New Site:

[domain.com...]

Thanks,
Rob

omoutop

9:58 am on Dec 20, 2006 (gmt 0)

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



Welcome to the webmasterworld flagtothefloor.

Since you use php is it safe for me to assume you are also using apache?
If so, the the htaccess redirect permanent may be of help to you.

Sort example:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^oldlocation.htm$ [mydomain...] [R=permanent]

If you are unfamiliar with the htaccess and mod_rewrite, you can find many usufull info here [webmasterworld.com ]

flagtothefloor

3:03 am on Dec 21, 2006 (gmt 0)

10+ Year Member



Thanks!

How do I incorporate that query string into this? Would it be:

RewriteRule [domain.com...] [domain.com...] [R=permanent]

or

RewriteRule Product.aspx?SKU$ [domain.com...] [R=permanent]

omoutop

6:55 am on Dec 21, 2006 (gmt 0)

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



I am guessing you have lots of products...
that way it is wise to use wildcharacters instead of lots of rewrite rules
try something like this:

RewriteRule ^product.aspx?SKU=([^/\.]+)/?$ product_info.php?products_id=$1 [L]

Again, I am not an expert in htaccess and this rule might not work at all, but the general idea still stands. Redirect any product.aspx page to product_info.php page and assign any SKU=? to product_id=?.

For a better understanding in htaccess, please consult the apache forum here in webmasterworld (this is where i learn the basics :-) )