Solved

Rewrite Help

Posted on 2009-06-27
6
208 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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

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 …
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.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

14 Experts available now in Live!

Get 1:1 Help Now