Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Apache rewrite

Posted on 2015-02-08
4
Medium Priority
?
93 Views
Last Modified: 2015-02-13
A user can arrive at our site passing various variables in the URL

e.g.

http://mysite.com/?func=search&term=blah&setting=enga
or
http://mysite.com/?func=search&setting=enga&term=blah

I want to be to be able to put a rewrite rule in that will take the value of "setting" and rewrite it to be "engb" regardless of where it is in string.

What would be the rewrite rule?
0
Comment
Question by:yelbow
  • 2
4 Comments
 
LVL 51

Expert Comment

by:Steve Bink
ID: 40598394
Why not do this programmatically when you handle the query string parsing?
0
 

Author Comment

by:yelbow
ID: 40598423
It's all embedded in third party code which we can't tinker with  - need to handle it on the way in with a mod rewrite or something.
0
 
LVL 51

Accepted Solution

by:
Steve Bink earned 1000 total points
ID: 40598976
You want something like this:
RewriteCond %{QUERY_STRING} (.*(?:^|&))key=val((?:&|$).*)
RewriteRule /path /path?%1other_val%2

Open in new window

Just replace "key=val" and "other_val" with their respective values.
0
 
LVL 18

Assisted Solution

by:Lucas Bishop
Lucas Bishop earned 1000 total points
ID: 40607441
I'm pretty sure this is the rewrite condition you want:

RewriteCond %{QUERY_STRING} ^(.+?&|)setting=[^&]*(?:&(.*)|)$ [NC]

Open in new window


Will need to dig into the correct RewriteRule to employ.

This would work if setting=enga was always at the end of the string:
RewriteCond %{QUERY_STRING} (.*(?:^|&))setting=((?:&|$).*)
RewriteRule ^ %{REQUEST_URI}?%1&setting=engb [R=301,L]

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

886 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