Forum Moderators: phranque

Message Too Old, No Replies

301 Redirect Syntax

         

jcrocker

6:17 pm on Aug 10, 2004 (gmt 0)

10+ Year Member



I am having some problems creating a 301 redirect in my .htaccess for a page that has changed names. This is what I have entered in my .htaccess:

redirect 301 /mydir/customer/product.php?productid=100001&cat=&page=1 [mysite.com...]

I think the problem has to to with the usage of the "?" and "&" in the document location. I have other 301 redirects established in my .htaccess for static pages that are working jsut fine. Any help would be great!

jatar_k

6:42 pm on Aug 10, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld jcrocker,

why not deliver it with php instead for that particular query string

There is an example in the user notes for header [php.net]

$url='http://www.mysite.com/mydir/customer/product.php?productid=100002&cat=&page=1';
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$url);
header("Connection: close");

jcrocker

6:52 pm on Aug 10, 2004 (gmt 0)

10+ Year Member



The site makes use of templates which I think would make using the PHP redirect complicated. My thought was it would be easier to manage all of the redirects in a single .htaccess file. Thanks alot for your suggestion but do you think it is possible to do what I want within the .htaccess?

jatar_k

7:02 pm on Aug 10, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I believe it is a syntax problem

Redirect permanent /mydir/customer/product.php?productid=100001&cat=&page=1 [mysite.com...]

using permanent instead of 301

take a look here
[httpd.apache.org...]

jcrocker

8:10 pm on Aug 10, 2004 (gmt 0)

10+ Year Member



Thanks again but still no luck...even using redirect permanent.

jdMorgan

3:47 am on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jcrocker,

Welcome to WebmasterWorld!

The problem is that the Redirect directive cannot "see" the query string appended to the URL. This is true on either many or all Apache servers -- I'm not sure which.

If you have access to mod_rewrite, the following code will do what you want:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^productid=100001&cat=&page=1$
RewriteRule ^mydir/customer/product\.php$ http://www.mysite.com/mydir/customer/product.php?productid=100002&cat=&page=1 [R=301,L]

This rule can be expanded to change only the productid and retain the other parameters if needed.

Jim

jcrocker

1:37 pm on Aug 11, 2004 (gmt 0)

10+ Year Member



jdMorgan...thanks so much!

Your suggestion worked just as I need!