Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Apache redirect ports based on (sub)domain name

Posted on 2006-11-14
18
Medium Priority
?
375 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 2000 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

618 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