Solved

Rewrite Help

Posted on 2009-06-27
6
203 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
Comment Utility
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
Comment Utility
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
Comment Utility
The flag was changed from P to L, so there's no proxying anymore.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 6

Author Comment

by:stewartacampbell
Comment Utility
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
Comment Utility
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
Comment Utility
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.

Join & Write a Comment

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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

10 Experts available now in Live!

Get 1:1 Help Now