Forum Moderators: phranque

Message Too Old, No Replies

301 redirect problems

         

blainehilton

11:48 pm on Jan 23, 2005 (gmt 0)

10+ Year Member



I am trying to send traffic from an old page on a site to the new page. I am using a .htaccess file with the following line:

redirect 301 /shop/product_info.php?cPath=60&products_id=70 [mystore.com...]

However it doesn't work. I was able to get this to work though:

redirect 301 /test www.test.com

So I believe the issue is related to the question marks, equal signs and so forth. I am thinking I need to comment these out somehow, but have not had luck using a variety of slashes and quotes.

Any help would be greatly appreciated.

--
Thanks in advance
Blaine

jdMorgan

2:55 am on Jan 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Blaine,

Use mod_rewrite instead; mod_alias doesn't handle query strings, but mod_rewrite does.

Jim

blainehilton

3:25 am on Jan 24, 2005 (gmt 0)

10+ Year Member



Thanks for that tip! I am now working on something along these lines:

RewriteEngine on
RewriteRule ^/shop/default.php?cPath=21 /shop/new.php?cPath=40 [R=301]

I have not been able to get this to work yet, but I will keep trying.

--
Thanks
Blaine

blainehilton

3:52 am on Jan 24, 2005 (gmt 0)

10+ Year Member



I've been trying a variety of possibilities and have not had any success. I'm first of all not sure what I need to comment out, I'm pretty sure I need a comment slash before the period in .php, but I'm not sure if I need one before an equal sign and/or ampersand. The link in the forum charter for [etext.lib.virginia.edu...] talks about escape characters, but says that it is dependent on the tool being used for when you need them. Is there a location I can find a list of everything that needs to be escaped?

Also I am trying to use this code:

RewriteRule ^/shop/default\.php\?cPath\=21 /shop/new.php?cPath=50 [R=301,L]

I always see the rewrite rules begin with a ^ character, however after reading about regular expressions it seems like a "$" would be better since I'm looking at the end of the line and not the start.

Any additional pointers would be appreciated.

--
Thanks
Blaine

jdMorgan

5:12 am on Jan 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, mod_rewrite is quite a bit more complex than mod_alias. That's the cost *and* the benefit of it. Query strings are handled separately in mod_rewrite, because query strings are not technically part of a URL but rather, data to be passed to the resource *at* the given URL, and because more powerful rewrites can be done by handling them separately. But here's an example to show you where you need to be heading:

RewriteCond %{QUERY_STRING} ^cPath=21$
RewriteRule ^shop/default\.php$ /shop/new.php?cPath=50 [R=301,L]

As far as anchoring and the details of mod_rewrite, there are links in our forum charter (link at top left) to explain regular expressions, anchoring and character-escaping, and also links to the Apache mod_rewrite documentation and User Guide. Highly-recommended reading to save you a lot of problems and wasted time...

Just for reference, you need to escape the following in normal regex patterns: ^$%.*+?\¦(){}[]

Within grouped alternates (inside square brackets) special rules apply; Under certain circumstances you will need to escape "^" and "-" and you'll always need to escape "]" since that character closes a group.

Jim