Solved

Apache redirect ports based on (sub)domain name

Posted on 2006-11-14
18
372 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
[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
  • 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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
 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

690 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