Dynamic to Static URL's - 301 Redirect Problem

Discuss practical ways rearrange URLs using mod_rewrite.

Dynamic to Static URL's - 301 Redirect Problem

Postby connoserv » Thu Aug 28, 2008 6:23 am

Hi all....

can anyone see a problem with this.........

Code: Select all
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /test\.php(\?([^\ ]*))?\ HTTP/1\.
RewriteCond %{QUERY_STRING} ^vendor=me&m=product_list&c=([^&]*)&wType=([^&]*)&wSize=([^&]*)$
RewriteRule ^test\.php$ /test_$2_$3_$1.html?   [L,R=301]


For SEO purposes and to stop google seeing both pages and hence classing them as duplicate content, my aim is to redirect the old dynamic urls to the new static ones as follows..

i.e.

test.php?vendor=me&m=product_list&c=21&wType=GGL&wSize=M08

... to ...

test_GGL_M08_21.html

at present these rules do nothing... if i remove the QUERY_STRING condition it redirects me to ...

test___.html

so i presume the problem lies within that condition?

if anyone could help me with this it would be greatly appreciated...

regards,

Sam.
connoserv
 
Posts: 3
Joined: Thu Aug 28, 2008 6:08 am
Location: Coventry, UK

Postby connoserv » Thu Aug 28, 2008 7:33 am

FIXED! :)
connoserv
 
Posts: 3
Joined: Thu Aug 28, 2008 6:08 am
Location: Coventry, UK

Postby richardk » Fri Aug 29, 2008 7:59 am

Next time please post your solution. Part of the problem is that % is used instead of $ for RewriteCond backreferences (variables).

You will have a problem with the query string variables being in different orders (it won't match m=product_list&c=21&wType=GGL&vendor=me&wSize=M08). With many query string variables it is easier to do the redirecting with PHP.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby connoserv » Sat Aug 30, 2008 2:48 am

Appologies for not posting the solution, i was in a rush at the time....

here's the fix

Code: Select all
RewriteCond %{THE_REQUEST}      ^[A-Z]{3,9}\ /test\.php(\?([^\ ]*))?\ HTTP/1\.
RewriteCond %{QUERY_STRING}      ^(.*&)?vendor=me&m=product_list&c=([^&]+)&wType=([^&]+)&wSize=([^&]+)(.*&)?$                        
RewriteRule ^test\.php$      /test_%3_%4_2.html?    [R=301,L]


regards,

Sam
connoserv
 
Posts: 3
Joined: Thu Aug 28, 2008 6:08 am
Location: Coventry, UK


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 19 guests

cron