Apache2Triad Help, Support and Development Forum Index Search Profile Log in to check your private messages Log in Register Memberlist Attachments Statistics Crew/Ranks Archive
 How do I code a simple redirect?
Post new topic Reply to topic
Author Message

Joined: 06 Apr 2005
Posts: 2

PostPosted: Sat Oct 29, 2005 3:41 am Reply with quoteBack to top

Thank you for your support in advance. The use of mod_rewrite in Apache is a many splendored thing I am certain, however my research into it has produced way too many examples and haven't quite gotten down to a straight-forward working example.

The scenario is 2 servers each running web services. One happily is our tried and trusted Apache2triad stable version; the other is hosting our destination site on a port other than 80, we'll say 8000. The object is for a web request on our first Apache2triad server of http://www.requestin.mysite.com to be redirected to http://www.requestout.mysite.com:8000. All I am asking for is a simple coding model to accomplish this within http.conf, without complicating it with additional files for php, .htaccess, perl, etc.

The redirection is nothing more than that; all requests to the subdomain requestin.mysite.com be simply handed over to requestout.mysite.com:8000. I have no issues that I am aware of getting to this point, such as setting up the virtual hosts, or what a document root is, etc. This behaviour of redirection may be termed as port forwarding, redirection, masking, etc., etc. In this case, a straightforward passing of the request to another machine will suffice.

What I am trying to circumvent is the following: I have to first go to my dns provider and enter my subdomain name and have it forward to the destination address. (The syntax is a little different, I would create requestin.mysite.com, then forward it to mysite.com:8000.) Second, I have to enter on my router to port forward all requests on port 8000 to the second server by it's static ip address like this: Label: myrequestout Port: 8000 IP: Alot of work, and it does work, but I am looking to reduce these steps to using mod_rewrite within http.conf. This means that requestin is a virtual host which will only redirect to requestout on port 8000. DNS has been assumed locally and is working (and is not port aware, hence where Apache comes in), Apache, and virtual hosting all are ready for the mod_rewrite to be coded in http.conf.

I have not included any of the examples in this context for a specific reason. If your code does this:

entered in web browser: http://requestin.mysite.com

then Apache redirects this to: http://requestout.mysite.com:8000

with a bonus of masking, and your code works, that is what I am looking for. Typing http://requestout.mysite.com:8000 into a browser works by itself given the facts above, but all i want to do is simplify to a subdomain and have it redirected, port forwarded, and masked. It sounds like alot and probably is in theory, as I can attest, but I am certain the actual code (and where to put what, or in step format as many have graciously guided us with if possible) would be just a few lines, but carries great value to many of us.

Thank You.

Note to Mr. Mancini: As more people's awareness of network administration grows, would you consider including BIND in your next release? After having sifted through the jargon, it can be setup as part of your application with the same effort as you have demonstrated to us. That would just be a home-run-killer-app, not that A2T isn't already. Also, would you entertain the idea of your next installer to include a dialog box to install only those applications requested? Thank you.
View user's profileSend private message
Joshua Meadows (DemoRic)

Joined: 29 Dec 2004
Posts: 783
Location: S.E. Kansas

PostPosted: Sat Oct 29, 2005 8:49 pm Reply with quoteBack to top

You could use mod_proxy to do this. There is a releated example for zope that you could modify for your use.


Or another.

(sorry these aren't specific examples on a2t, but it should be simple enough to do)

you could also setup a tunnel
View user's profileSend private messageYahoo MessengerICQ Number

Joined: 06 Apr 2005
Posts: 2

PostPosted: Mon Oct 31, 2005 4:24 pm Reply with quoteBack to top

I feel confident stating that your answer was actually better than the question - zserver and esp the tunnel - I can't wait to experiment with. Your links did do one thing right on target - point out to me what I was doing wrong.

Originally, as stated, I would have to go to the registrar, create a subdomain, then forward it to any url, then in a separate step add masking (which used to cost about 5 bucks, but free now). Now, in Apache, I can do it all in one code example with virtual hosting:

<VirtualHost *:80>
    ServerAdmin admin@mysite.com
    ErrorLog logs/requestin.mysite.com-error_log
    CustomLog logs/requestin.mysite.com-access_log combined
    ServerName requestin.mysite.com
    RewriteEngine On
    RewriteLog logs/rewrite_log.log
    RewriteLogLevel 0
    RewriteRule ^/(.*)$ http://requestout.mysite.com:8000 [L]

The last line, the actual RewriteRule, is what I was looking for the syntax for. As best as I can tell, redirecting Apache to an internal server is a separate process, so at this point I would still have the step of configuring my router. This example works exactly the same as the information i would enter at my registrar to produce the same effect.

What is interesting, is that to remove masking, the flag [R] would be appended at the end of the RewriteRule. Seems weird that masking would be on by default, and code would be added to turn it off (it would cost five bucks to remove the [R]). That's why I thought extra code would be needed to mask, not the other way around.

Though it doesn't appear that it's needed being the only rule statement, masking stops if I omit the [L] flag above, so I made it explicit.

Thank you.
View user's profileSend private message
Display posts from previous:      
Post new topic Reply to topic

 Jump to:   

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum
Powered by phpBB © 2001, 2002 phpBB Group :: FI Theme
All times are GMT