Solved

Help with RewriteRule

Posted on 2006-11-28
8
213 Views
Last Modified: 2010-03-04
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


0
Comment
Question by:merimax
  • 4
  • 3
8 Comments
 
LVL 13

Expert Comment

by:rhickmott
ID: 18029288
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]


0
 
LVL 16

Expert Comment

by:HackneyCab
ID: 18059419
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.
0
 

Author Comment

by:merimax
ID: 18059470
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?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 16

Accepted Solution

by:
HackneyCab earned 125 total points
ID: 18059479
Try adding a question mark to the end of the rewrite destination, but nothing after the question mark:

RewriteRule ^mm5/merchant.mvc$ %1.html? [R=301]

I've never used that, so I don't know if it will also show the question mark, or if it's smart enough to realise that it's being given the brush-off.
0
 

Author Comment

by:merimax
ID: 18059489
That did it! Thank you.
0
 
LVL 16

Expert Comment

by:HackneyCab
ID: 18059514
Does it show the question mark, or is Apache smart?
0
 

Author Comment

by:merimax
ID: 18059551
Apache is smart. It does not show the question mark.
0
 
LVL 16

Expert Comment

by:HackneyCab
ID: 18059597
Excellent. (Cue Mr. Burns' finger-tremble.)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question