Solved

Apache rewrite

Posted on 2015-02-08
4
83 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 50

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 50

Accepted Solution

by:
Steve Bink earned 250 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 16

Assisted Solution

by:Lucas Bishop
Lucas Bishop earned 250 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

21 Experts available now in Live!

Get 1:1 Help Now