Solved

Apache redirect ports based on (sub)domain name

Posted on 2006-11-14
18
368 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
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.

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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

25 Experts available now in Live!

Get 1:1 Help Now