?
Solved

Rewrite Help

Posted on 2009-06-27
6
Medium Priority
?
221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 4

Accepted Solution

by:
martinewski earned 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

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…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

771 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