Solved

Help with RewriteRule

Posted on 2006-11-28
8
214 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
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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