.htaccess redirect

driveflexfuel

New Member
Messages
159
Reaction score
0
Points
0
This is an example of our old dynaimc product URL:
http://www.site.com/Merchant2/merchant.mvc?Screen=PROD&Product_Code=cm028-ak47-airsoft&Category_Code=&Store_Code=R

we are now using static pages

We need htaccess to reconize the product code which is cm028-ak47-airsoft then smiply redirct with 301 to the new static page which is http://www.site.com/cm028-ak47-airsoft.html

any help is greatly appreciated


Is this something that can be edited to work

# Enable mod_rewrite, start rewrite engine
Options +FollowSymLinks
RewriteEngine on
#
# Internally rewrite search engine friendly static URL to dynamic filepath and query
RewriteRule ^product/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?product=$1&color=$2&size=$3&texture=$4&maker=$5 [L]
#
# Externally redirect client requests for old dynamic URLs to equivalent new static URLs
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?product=([^&]+)&color=([^&]+)&size=([^&]+)&texture=([^&]+)&maker=([^\ ]+)\ HTTP/
RewriteRule ^index\.php$ http://example.com/product/%1/%2/%3/%4/%5? [R=301,L]
 
Last edited:

marshian

New Member
Messages
526
Reaction score
9
Points
0
I haven't tested it, but I think something like this should work:
Code:
RewriteEngine on
RewriteRule ^Merchant2/merchant\.mvc\?(.*&)?Product_Code=([^&]+)(&.*)? /$2.html [R=301,L]
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Code:
RewriteCond  %{REQUEST_URI}  ^/Merchant2/merchant.mvc
RewriteCond %{QUERY_STRING} Product_Code=([^&]*)
RewriteRule  .*  /%1.html? [R=301,L]

Note: This does not test that you have a product file for the Product Code.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
RewriteRules don't match against the query string. You'll need to use a RewriteCond:

Code:
RewriteCond %{QUERY_STRING} (^|&)Product_Code=([^&]*)
RewriteRule ^/?Merchant2/merchant\.mvc /%1.html [R=301]
Depending on how exactly the site is arranged, you might need to remove the leading slash from the replacement string.

I'm assuming when you say "We need htaccess to reconize the product code which is cm028-ak47-airsoft", the "cm028-ak47-airsoft" is merely an example and you want the rewrite to work with any product code (you might want to work on your writing clarity).

When you're posting code or configuration, use one of the
Code:
, [PHP] or [HTML] tags to separate it from the rest of the post, as marshian and I have done. It makes it much easier to read.
 
Last edited:
Top