Solved

Help with RewriteRule

Posted on 2006-11-28
8
216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

717 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