Link to home
Start Free TrialLog in
Avatar of merimax
merimax

asked on

Help with RewriteRule

I need the proper Apache RewriteRule to do the following:

Current URL:
http://www.domain.com/mm5/merchant.mvc?Screen=PROD&Store_Code=N&Product_Code=LXH_GTLAT8390-10

needs to be permanently redirected to:
http://www.domain.com/LXH_GTLAT8390-10.html

Basically I need what comes immediately after the words "Product_Code" to become the name of the file.

Thanks for your help


Avatar of Robin Hickmott
Robin Hickmott

What re you trting to do?

Redirect the long domain to the short (guessing so) If so then

RewriteEngine On
RewriteRule ^merchant\.mvc.*Product_Code=(.*)$ /$1.html [r]

Or the short to the long which would be

RewriteEngine On
RewriteRule ^(*.)\.html$ /mm5/merchant.mvc?Screen=PROD&Store_Code=N&Product_Code=$1 [r]


Try the following in a .htaccess file for the top-level directory:

RewriteCond %{QUERY_STRING} Product_Code=([a-zA-Z0-9_-]+)
RewriteRule ^mm5/merchant.mvc$ %1.html [R=301]

Let me know if that does not work.
Avatar of merimax

ASKER

RewriteCond %{QUERY_STRING} Product_Code=([a-zA-Z0-9_-]+)
RewriteRule ^mm5/merchant.mvc$ %1.html [R=301]

This works great but it copies the query string. How do I stop it from copying the query string?
ASKER CERTIFIED SOLUTION
Avatar of HackneyCab
HackneyCab
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of merimax

ASKER

That did it! Thank you.
Does it show the question mark, or is Apache smart?
Avatar of merimax

ASKER

Apache is smart. It does not show the question mark.
Excellent. (Cue Mr. Burns' finger-tremble.)