Forum Moderators: phranque

Message Too Old, No Replies

htaccess rewrite individual dynamic to static url

htaccess rewrite individual dynamic to static url

         

webwest

11:06 pm on Dec 10, 2009 (gmt 0)

10+ Year Member



We have a client moving from a Windows server to FreeBSD server with Apache. For SEO reasons, all the product and category codes will change to reflect what the product or category really is. So global rewrites won't work since the new product and category codes will be different.

I've searched this forum and others but can't seem to find a working solution. Please forgive me if this has already been said somewhere else here.

How would I 301 redirect this product:

domain.com/shop/item.asp?itemid=1319
to
domain.com/prod/new-product-6930.html

I've tried many variations but I can't get any to work. It seems like this would work but doesn't:

RewriteEngine on
Options +FollowSymLinks
RewriteCond %{QUERY_STRING} itemid=1319 [NC]
RewriteRule ^http://www.domain.com/prod/new-product-6930.html? [R=301,L]

Any help is appreaciated. Thanks!

webwest

11:52 pm on Dec 10, 2009 (gmt 0)

10+ Year Member



Figures that I'd figure it out right after I posted. This works:

RewriteCond %{QUERY_STRING} itemid=1319 [NC]
RewriteRule (.*) [domain.com...] [R=301,L]

g1smd

2:36 am on Dec 11, 2009 (gmt 0)

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



If you can replace the
.*
with something a little bit more specific like
\.html
or something, the system won't have to look at the RewriteCond line when the request is for a CSS file, an image, robots.txt and so on.

That will speed things up a bit.