Forum Moderators: phranque

Message Too Old, No Replies

.htaccess redirects

         

Imaulle

1:09 am on Jul 1, 2009 (gmt 0)

10+ Year Member



Hello! I am having some issues trying to get the server to forward some links..

this part here works correctly...


RewriteCond %{QUERY_STRING} ^cPath=46$
RewriteRule ^index\.php$ /product_info.php?products_id=693 [R=301,L]

but this only forwards /index.php?cPath=46 to /product_info.php?products_id=693

but sometimes the link will be /index.php?cPath=46&osCsid=g7crucvfas6ejfkbas7o46eig2

how do I get it to catch both /index.php?cPath=46 AND /index.php?cPath=46&osCsid=g7crucvfas6ejfkbas7o46eig2

the part after &osCsid= will always be random so I'm not sure how to do this...

thank you!

g1smd

1:29 am on Jul 1, 2009 (gmt 0)

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



The $ symbol expressly told the RewriteCond that *nothing* was to follow the '46'.

Change $ to be &? (ampersand followed by question mark) to allow another parameter to follow.

Your target should include the domain name so that it fixes www and non-www issues for *this* '46' URL within *this* rule.

Your rule caters for '/index.php' but does not cater for just '/' and that is a problem. Make it cater for both URLs.

You didn't say whether the osCid parameter was to be 'dropped' in the redirect, or whether it carries over.

Imaulle

1:38 am on Jul 1, 2009 (gmt 0)

10+ Year Member



kk that fixed the '46' issue

here is the entire .htaccess


RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

RewriteCond %{QUERY_STRING} ^cPath=46&?
RewriteRule ^index\.php$ /product_info.php?products_id=693 [R=301,L]

I still need to fix the www and non-www issue even though I have that first cond/rule set?

thanks for your reply.

Imaulle

1:42 am on Jul 1, 2009 (gmt 0)

10+ Year Member



oh! how do I make it carry over the osCid?

g1smd

1:42 am on Jul 1, 2009 (gmt 0)

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



Yes.

Consider a non-www request for cpath=46.

First rule redirects to www.

Second rule redirects to 'product.info'.

You have a Redirection Chain.

PageRank is *lost* on the second redirect.

Add the domain name to the target of the second rule. Fix it so that both 'index.php' and '/' trigger the rule.

Swap the order of the two rules so that the generic 'non-www to www' rule is listed last.

Be aware that your non-www redirect code does not fix a www request with appended port number leaving it open to Duplicate Content indexing. There's better code for this redirect, code that does not leave such a 'hole'.

As you haven't escaped the period on one of the conditions, be aware that the rule would work for a domain name of example.com as well as exampleZcom or example~com or example8com etc.

jdMorgan

2:02 am on Jul 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Fixing the points brought up so far...

RewriteEngine on
#
RewriteCond %{QUERY_STRING} ^cPath=46(&.*)?$
RewriteRule ^(index\.php)?$ http://www.example.com/product_info.php?products_id=693%1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Jim

Imaulle

2:09 am on Jul 1, 2009 (gmt 0)

10+ Year Member



awesome works perfectly. thank you gents!