Solved

Rewrite Help

Posted on 2009-06-27
6
216 Views
Last Modified: 2012-05-07
Hi I am trying to write a rewrite rule that will redirect any traffic to a specific php file, to a port on the server instead. While it is still on the same server, the server now has a subdomain too.

The redirect must save all the query string after it.

The following is an example of what I need to do:

http://www.mydomain.com/thefile.php?userkey=xxxxxxxxx&nextinfo=yyyyyyyyyy&moreinfo=zzzzzzzzzz&lastinfo=000000000
to
http://subdomain.mydomain.com:12345/xxxxxxxxx/thefile?nextinfo=yyyyyyyyyy&moreinfo=zzzzzzzzzz&lastinfo=000000000

As you can see, its really only xxxxxxxxx that needs to be extracted and moved, while the other query strings can stay in the same place.

I have tried the folowing:
RewriteCond %{query_string} userkey\=(.+?)&(.+)
RewriteRule ^thefile\.php http://subdomain.mydomain.com:12345/%1/thefile [P]

But this seems like a bad way of doing it, and doesnt seem to be working as it should. I dont really want to proxy anything and I think Ive got myself tied up in knots!

Can anybody help? Max points as I need a solution asap!

Thanks.
0
Comment
Question by:stewartacampbell
  • 3
  • 3
6 Comments
 
LVL 4

Accepted Solution

by:
martinewski earned 500 total points
ID: 24729760
It looks like this could do it.

RewriteEngine on
 
RewriteCond %{query_string} userkey\=(.+?)&(.+)
RewriteRule ^thefile\.php http://subdomain.mydomain.com:12345/%1/thefile?%2 [L]

Open in new window

0
 
LVL 6

Author Comment

by:stewartacampbell
ID: 24729814
That did indeed do it.

Points are yours.

Out of interest though, could you advise any way of doing it without proxying? Bear in mind the port can be the main webby address, doesnt need to use the new subdomain.

Im just so sure I should be able to do this without using mod_proxy.
0
 
LVL 4

Expert Comment

by:martinewski
ID: 24729945
The flag was changed from P to L, so there's no proxying anymore.
0
Save the day with this special offer from ATEN!

Save 30% on the CV211 using promo code EXPERTS30 now through April 30th. 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 6

Author Comment

by:stewartacampbell
ID: 24730294
Ah sorry I forgot to mention, this has to be invisible to the client.

When using the [L] flag the following is returned to the browser (looking using Wireshark)

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved.....

This breaks the client.

It has to be invisible to the client.

Any ideas?
0
 
LVL 4

Expert Comment

by:martinewski
ID: 24731266
In that case I think you would have to use php to get the file contents and output to thefile.php.

mod_proxy doesn't pass variables to the destination, that's why it wouldn't work with mod_rewrite.
0
 
LVL 6

Author Comment

by:stewartacampbell
ID: 24779466
Strangely enough, I managed to get it working!

RewriteCond %{query_string} userkey\=(.+?)&(.+)
RewriteRule ^thefile\.php http://%{SERVER_NAME}:12345/%1/thefile?%2 [NE,QSA,L]

The above managed to avoid proxying at all (which I was already sure didnt have to be done).

I had a couple hours sleep and woke up with the realisation that it didnt matter about the subdomain, since they were both located on the same server, and the local redirect worked wonders.

Im not even sure the %2 needs to be there since QSA is added, but its working and Im not going to mess with it!

Thanks again.
0

Featured Post

Don't miss ATEN at NAB Show April 24-27!

Visit ATEN at NAB Show to learn how our "Seamlessly Entertaining" solutions deliver fast, precise video streaming without delays for the broadcasting and media environment. ATEN will showcase its 16x16 Modular Matrix Switch (VM1600) and KVM Over IP Solution (KE6900 series).

Question has a verified solution.

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

Suggested Solutions

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…
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 …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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