Solved

Apache redirect ports based on (sub)domain name

Posted on 2006-11-14
18
367 Views
Last Modified: 2008-02-20
I need to redirect mail.domain.com:8000 to mail.domain.com

Can this be done with apache (I think it can, but don't know how).  If not, where should I go next.
0
Comment
Question by:jtgraphic
  • 11
  • 5
  • 2
18 Comments
 
LVL 43

Expert Comment

by:ravenpl
ID: 17944888
Is apache configured alredy to listen on port 8000? Or do the mail.domain.com:8000 is working already?
If so, then use mod_rewrite. Put into the .htaccess file located in document root for mail.domain.com:8000
RewiteEngine On
RewriteCond %{SERVER_PORT} ^8000$
RewriteRule (.*) http://mail.domain.com/$1 [L,R]
0
 

Author Comment

by:jtgraphic
ID: 17946677
Ahh... Ok, maybe I wasn't clear.

I have an independent mail server running on the same server.  Its webmail CAN use port 80, but I am using apache on that port, so I redirected webmail to port 8000.  When I go to mail.domain.com I get the apache server, and when I go to mail.domain.com:8000, I get the webmail server.  I would like mail.domain.com to go to the mail server (redirected by apache or some other source).

-JKT
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17946726
Then You need the other way.
Put into the .htaccess file located in document root for mail.domain.com
RewiteEngine On
RewriteEngine %{HTTP_HOST} ^mail.domain.com$ //if user put mail.domain.com in it's browser
RewriteEngine %{HTTP_HOST} !^$ //and it's not empty - damn HTTP/1.0 clients...
RewriteRule (.*) http://mail.domain.com:8000/$1 [L,R]
0
 

Author Comment

by:jtgraphic
ID: 17946742
::Crosses Fingers::

I'll let you know.
0
 

Author Comment

by:jtgraphic
ID: 17946844
I received this error in the log:

[Wed Nov 15 09:05:18 2006] [alert] [client 192.168.0.253] C:/wamp/www/.htaccess: Invalid command 'RewiteEngine', perhaps mis-spelled or defined by a module not included in the server configuration

I have the rewrite module activated as well.  Now would probably be a good time to say I have:

Apache/2.0.59 (Win32) w/ PHP/5.2.0 Server
0
 
LVL 57

Expert Comment

by:giltjr
ID: 17946881
--> RewriteEngine %{HTTP_HOST} ^mail.domain.com$ //if user put mail.domain.com in it's browser
--> ewriteEngine %{HTTP_HOST} !^$ //and it's not empty - damn HTTP/1.0 clients...

Not sure, but did you include the "// comments"?  If so I think you need to remove it.
0
 

Author Comment

by:jtgraphic
ID: 17946898
I didn't.

Here is the exact text of the .htaccess file:

RewiteEngine On
RewriteEngine %{HTTP_HOST} ^mail.domain.com$
RewriteEngine %{HTTP_HOST} !^$
RewriteRule (.*) http://mail.domain.com:8000/$1 [L,R]
0
 

Author Comment

by:jtgraphic
ID: 17946912
Rewrite was mispelled, but that didn't fix it :-/
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17946948
//Oh my - there should be RewriteCond !
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mail.domain.com$
RewriteCond %{HTTP_HOST} !^$
RewriteRule (.*) http://mail.domain.com:8000/$1 [L,R]
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:jtgraphic
ID: 17947016
Exact Text:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mail.domain.com$
RewriteCond %{HTTP_HOST} !^$
RewriteRule (.*) http://mail.domain.com:8000/$1 [L,R]

Error:

[Wed Nov 15 09:25:19 2006] [alert] [client 127.0.0.1] C:/Wamp/www/.htaccess: Invalid command 'RewriteEngine', perhaps mis-spelled or defined by a module not included in the server configuration
0
 

Author Comment

by:jtgraphic
ID: 17947064
My Mistake.

It helps when I change mail.domain.com to what it really is.
0
 

Author Comment

by:jtgraphic
ID: 17947083
so...

It seems like its a simple redirect.  I was looking for more of a "mask."  I'm inclined to accept the answer, because I wasn't 100% clear, but do you have any suggestions for masking?
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17947130
> I was looking for more of a "mask."
What mask? Maybe this mask?
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^mail\.(.*)$
RewriteRule (.*) http://mail.%1:8000/$1 [L,R]
0
 

Author Comment

by:jtgraphic
ID: 17947488
When I go to mail.domain.com, it just switches to mail.domain.com:8000.  Is there a way to keep it mail.domain.com?
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 500 total points
ID: 17947583
> When I go to mail.domain.com, it just switches to mail.domain.com:8000.  Is there a way to keep it mail.domain.com?
No. if there is no port, it defaults to 80, so in fact those are exactly same: http://mail.domain.com/ http://mail.domain.com:80/
If it wasn't so how will You know whether it's to apache's webpage or webmail's webpage?

If there wasn't any webpage at port 80 at all, we could mimic it at serverside with iptables firewall rules...
0
 

Author Comment

by:jtgraphic
ID: 17947617
Ahh ok.  I guess it makes sense.  I'll have to wait until I break my email server out into its own machine and can give it a separate IP address.  Thanks for your help.
0
 
LVL 57

Expert Comment

by:giltjr
ID: 17948332
You might be able to keep it as mail.domain.com, but I am not 100% sure.

Apache can be used as a reverse proxy sever.  You SHOULD be able to configure Apache to accept http://mail.domain.com and then proxy it back to http://127.0.0.1:8000.  In fact even after you move the e-mail sever to another box you could still leave Apache proxying the request and just change http://127.0.0.1:8000 to http://newnameoraddress:80


 
0
 

Author Comment

by:jtgraphic
ID: 17948683
Interesting.  I'll follow up on that.  I wish I could give bonus points.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
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 …
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…
This video discusses moving either the default database or any database to a new volume.

744 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

12 Experts available now in Live!

Get 1:1 Help Now