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
Solved

Apache redirect ports based on (sub)domain name

Posted on 2006-11-14
18
370 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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). #…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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