Solved

Redirect PHP Requests to Another Server?

Posted on 2004-04-29
10
1,479 Views
Last Modified: 2012-08-13
This is my scenario:

One Red Hat 8.0 server with Apache 2.0.4x with a public IP address. This server hosts only one static page at http://mydomain.com/index.html (neither PHP, nor anything installed)

One Fedora Core 1 Server with Apache 1.3.29. This server hosts is connected to the same LAN as the Red Hat Server, but has no public IP address, with PHP, MySQL and other stuff installed.

Then, what you get when you type http://mydomain.com/index.html in your browser, is the index.html file served by the first Red Hat 8.0 Server. This is quite simple, and it works ok, but here's my question:

Is it possible to "redirect" some request from the Red Hat to the Fedora Core?
For example, this is what I'd need:

If you type http://mydomain.com in the browser, you get the index.html hosted on the Red Hat Server, BUT If you type http://mydomain.com/stock in the browser, you get a complete dynamic PHP application served by the Fedora Core Server

Is this possible? If so, how can I accomplish this??

Thanks so much in advance, and sorry about my english
0
Comment
Question by:dsuarezuy
  • 5
  • 3
  • 2
10 Comments
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10949247
try this..

<meta http-equiv="REFRESH" content="0; URL=http://url">

0/1 - seconds. or you can specify as your wish..but it redirects to u r specified URL from this page..to new URL

R.K

0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10949282
see also..

I guess there are two ways around this. One is to use a more advanced Apache
proxy passing technique, such as that mentioned in the Apache documentation at:
http://httpd.apache.org/docs-2.0/mod/mod_proxy.html
" Only the HTTP response headers specifically mentioned above will be rewritten.
Apache will not rewrite other response headers, nor will it rewrite URL references
inside HTML pages. This means that if the proxied content contains absolute URL
references, they will by-pass the proxy. A third-party module that will look inside
the HTML and rewrite URL references is Nick Kew's mod_proxy_html. " 
This more advanced module can be downloaded from
http://apache.webthing.com/mod_proxy_html/

The other is, I guess, for Webmin to alter its URLs itself to refer to addresses
in the proxy's address space. I presume that this is the purpose of the "proxprefix"
directive in the webmin setup file but alas I am unable to get it to work.

In httpd.conf ------

LoadModule proxy_module    libexec/libproxy.so
AddModule mod_proxy.c
<IfModule mod_proxy.c>
ProxyRequests On

<Directory proxy:*>
Order deny,allow
Deny from all
Allow from all
</Directory>
ProxyVia On
</IfModule>

ProxyIOBufferSize 1048576
NameVirtualHost www.domainname.com:10000
<VirtualHost  www.domainname.com:10000>
ProxyPass /   http://www.webmindomain.com:10000
</VirtualHost>

R.K
0
 
LVL 10

Expert Comment

by:Mercantilum
ID: 10949576
Actually what you need is to get Apache rewriting the URL to go to somwhere else.
This is typically a job for Apache mod_rewrite  

    (http://httpd.apache.org/docs/mod/mod_rewrite.html)
    (http://httpd.apache.org/docs/misc/rewriteguide.html)

Include these lines in your httpd.conf file (or within your VirtualHost directive if you use them)

RewriteEngine On
RewriteCond  %{HTTP_HOST}   ^mydomain\.com
RewriteRule  ^/(stock)  http://fedoraserver.com/cgi-bin/fedora.php?item=$1 [L,R]


For instance that would redirect urls of http://mydomain.com with stock subdir to your fedora server.
It will then execute cgi-bin/fedora.php giving one argument item being stock.
If you need the two url to be on the same server, the line is to be changed (otherwise the rule would loop :)
0
 
LVL 10

Expert Comment

by:Mercantilum
ID: 10949633
This assume as well that these 2 lines are in your httpd.conf (as they are usually) to load the mod_rewrite module

LoadModule rewrite_module     /usr/lib/apache/mod_rewrite.so
   ....
AddModule mod_rewrite.c


(the path may be different though)
0
 

Author Comment

by:dsuarezuy
ID: 11131969
Mercantilum,
Thanks for your valuable help. I've tried your solution on my intranet with 2 PC's and and it seems to work fine, but maybe this is not what I need

When I type http://PC1/stock, I'm "redirected" to http://PC2/default.php, which is the expected behavior, but my IE address bar text changes to "http://PC2/default.php" (As if I had typed it). Since "PC2" will be accesible directly ONLY from PC1 (with the public IP address) and it won't be accesible for internet users, I think this wouldn't work.

Please correct me if I'm wrong.

This is what I finally added to httpd.conf file to test what you suggested to me:
RewriteEngine On
RewriteCond  %{HTTP_HOST}   ^localhost
RewriteRule  ^/(stock)  http://192.168.1.2/default.php

If I type "http://localhost", the page is served by Apache residing on my PC (PC1)
If I type "http://localhost/stock", the page is served by PC2 (Fedora)...BUT my IE address bar changes to "http://192.168.1.2/default.php" which it really won't be accesible by user.

This is what I expect:
http://www.apache.com (served by RedHat)
http://www.apache.com/stock (served by Fedora)

Thanks for your help
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 10

Accepted Solution

by:
Mercantilum earned 150 total points
ID: 11132347
So, in this case you need is your RedHat apache server to server as a reverse proxy only in the case of http://www.apache.com/stock .

Config for the RedHat server:

>>>
RewriteEngine   on
RewriteRule    ^/stock$    http://192.168.1.2/default.php  [P,L]
ProxyPassReverse  /  http://www.apache.com/
<<<

This should detect on the global server (redhat) if the URL is /stock.
If it is the case, the mod_rewrite simulates a ProxyPass request (P) to http://192.168.1.2/default.php
The ProxyPassReverse ensures the replies from the 192.168.1.2 server are URL labelled http://www.apache.com
0
 

Author Comment

by:dsuarezuy
ID: 11133207
Mercantilum, your solution worked perfectly for me, but I got a last doubt (I increased the points since I think it's a complementary question)

http://www.apache.com (served by RedHat WORKS Perfectly !!)
http://www.apache.com/stock (served by Fedora WORKS Perfectly !!)

but http://www.apache.com/stock/ (throws a 404 error) (Note the last slash)
0
 
LVL 10

Expert Comment

by:Mercantilum
ID: 11133235
Ok change the rule as

RewriteEngine   on
RewriteRule    ^/stock[\/]{0,1}$    http://192.168.1.2/default.php  [P,L]
ProxyPassReverse  /  http://www.apache.com/

This will allow /stock and /stock/  (note the backslash before the / in the [...])
0
 
LVL 10

Expert Comment

by:Mercantilum
ID: 11133239
Actually the [] are not necessary... just in case we had some other choice after ;-)
0
 

Author Comment

by:dsuarezuy
ID: 11133538
Thanks so much for your help !!
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP clean up nicely even if user abort 13 57
500 Internal Server Error When I Run Code Igniter 4 60
Xampp Not Stopping 9 40
PHP Upload using Uploadify 4 70
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 your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

17 Experts available now in Live!

Get 1:1 Help Now