Solved

Rewrite Help

Posted on 2009-06-27
6
215 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

Question has a verified solution.

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

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…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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