Solved

Help with RewriteRule

Posted on 2006-11-28
8
211 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 16

Accepted Solution

by:
HackneyCab earned 125 total points
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:merimax
Comment Utility
That did it! Thank you.
0
 
LVL 16

Expert Comment

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

Author Comment

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

Expert Comment

by:HackneyCab
Comment Utility
Excellent. (Cue Mr. Burns' finger-tremble.)
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now