redirect server wide [hostname]/alias to mail.[hostname]


Hi, I want to be able to redirect any http://domainonserver.com/alias to http://mail.domainonserver.com , I know it can be done on http.conf, I just dont know how because i dunno how to extract the domainonserver.com hostname and to wirte the rule.. can someone help please..
RIOSmxAsked:
Who is Participating?
 
ahoffmannCommented:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^[/]*squirrelmail
RewriteCond %{HTTP_HOST}   !^mail\.(.*)
RewriteCond %{HTTP_HOST}   !^webmail\.(.*)
RewriteRule (.*)     http://mail.%1/$1/ [L,R]
# test above with one of the HTTP_HOST conditions first, then test with the other one
# if both work, then test with both conditions enabled

RewriteCond %{REQUEST_URI} ^[/]*squirrelmail
RewriteCond %{HTTP_HOST}   ^www\.(.*)
RewriteRule (.*)     http://webmail.%1/$1/ [L,R]

> if someone access http://domain1/file
> redirect to ---> http://mail.domain1/
this is an invalid FQDN and hence can not be matched, or it is local on your host then you can fix that on this host itself ;-)

> access http://mail.mydomain.net/squirrelmail
> redirect to --> http://webmail.mydomain.net
this violates your other conditions/requirements
Either you rethink about this rule, or you need to make one single unique rule for each of your domains.

As you want to have sophisticated regex and redirect, you should enable logging and check your logfiles.
0
 
ahoffmannCommented:
RewriteEngine On
RewriteCond %{HTTP_HOST}   !^domainserver.com$
RewriteRule ^/(.*)         http://mail.domainserver.com:%{SERVER_PORT}/$1 [L,R]
0
 
RIOSmxAuthor Commented:

thanks for the reply , sorry , but "domainserver.com" was only an example, I would NOT have a fixed domain for every domain accessed, it will depend on the domain used to access... for example:

if someone access http://domain1/file
redirect to ---> http://mail.domain1/

if someone access http://domain2/file
redirect to ---> http://mail.domain2/

....and so on domain3,4,5,6...

Some could prolly figure it out already with your example provided but not me i am not familiar with httpd.conf
hope you could
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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

if you have different pattern for domainserver, either use a separate RewriteCond for each, or try to write a matching regex
0
 
RIOSmxAuthor Commented:

I am sorry I am slow i been trying to undertand regexp forever no luck, http module are even more complex for my...  i think its almost there the thing is...

RewriteCond %{HTTP_HOST}   !^domainserver.\.com$

the condition applies only to  domainserver.com domain isnt it, I wan it to work for any domain... :(
0
 
ahoffmannCommented:
RewriteCond %{HTTP_HOST}   !^[a-zA-Z0-9][a-zA-Z0-9-]+.\.com$
0
 
ClickCentricCommented:
Do you want to actually redirect (ie send a redirect header to the browser) or just have the content of the new location show up?  And in your example:

if someone access http://domain1/file
redirect to ---> http://mail.domain1/

if someone access http://domain2/file
redirect to ---> http://mail.domain2/

Is 'file' always the same?  You mentioned an alias in your original post, do you mean a user alias in ~alias format?  This is pretty simple to do, but I need to know exactly what you're starting with and what you want the end result to be.
0
 
RIOSmxAuthor Commented:

Yes, the file after the domain is always the same, what I am trying to do is to redirect an old way to get to webmail...   the old way was somedomain/squirrelmail the new way is mail.somedomain ... I want to be able to put that condition server wide this way any domain on the server that is type with the www.domain.com/squirrelmail directory after the domain should be redirected to mail.domain.com where  domain.com can be any domain .net .com .com.mx whatever hits to the box...  hope you can help me, it still not clear to me with the help of the others..
0
 
RIOSmxAuthor Commented:
sorry, yes redirect will be better, this way they will notice the access to webmail has changed..
0
 
ClickCentricCommented:
I'm pretty sure I can help, just need to know if your web server is apache and if so, what version it is (1.3 or 2.0)?
0
 
RIOSmxAuthor Commented:

tnx, its apache 1.3
0
 
ClickCentricCommented:
I THINK this should work (though I can't test it right now and I can't remember for certain if optional non-matching subpatterns can be used):

RedirectMatch (?:www\.)?(.*)/suirrelmail$ http://mail.$1.com

If not then:

RedirectMatch (www\.)?(.*)/suirrelmail$ http://mail.$2.com

should work.
0
 
RIOSmxAuthor Commented:

isnt that expecting a www. before the domain? could you make it as a wildcard so that www.domain mail.domain domain or whatever.domain will work ?
0
 
ClickCentricCommented:
Well, it's not 'expecting' one, just it allows for there to be one.  If you use a wildcard, the problem becomes that the actual domain name (domain.com) won't be able to be resolved.  So if someone went to www.domain.com/squirrelmail, it would redirec to http://mail.www.domain.com which may or may not work depending on how you have things configured.  The extra step is to avoid worrying about the www. part.
0
 
RIOSmxAuthor Commented:
yet one more Q, arent you redirecting to domain.COM , i dont know if the domin is a .com .net .org or any else, it should whatever the extension of the domain typed..
0
 
RIOSmxAuthor Commented:

i tryed out both , not working.. it give me a not found error..
0
 
ClickCentricCommented:
Oh, oops..that was a brain glitch..forget my previous post about it, change it to:


 THINK this should work (though I can't test it right now and I can't remember for certain if optional non-matching subpatterns can be used):

RedirectMatch (?:www\.)?(.*)/suirrelmail$ http://mail.$1

If not then:

RedirectMatch (www\.)?(.*)/suirrelmail$ http://mail.$2

should work.
0
 
ahoffmannCommented:
Redirect* directives cannot be used 'cause they only get the URL-path part
Redirect* directives are used for the server itself

You have to use either mod_rewrite or mod_proxy, as I suggested. What is wrong with that?
0
 
ClickCentricCommented:
Oh, hmm...yeah, forgot about that.  I wasn't anywhere I could check at the time.   It would need a rewrite rule, it would just have to be careful for dealing with subdomains and varying TLD's.
0
 
RIOSmxAuthor Commented:

ahoffman, it seems to me that RewriteCond %{HTTP_HOST}   !^domainserver.\.com$ is looking for domainserver.com in the domain name, my rule need to apply to any domain on the server..
0
 
RIOSmxAuthor Commented:
sorry, also note that RewriteCond %{HTTP_HOST}   !^[a-zA-Z0-9][a-zA-Z0-9-]+.\.com$ seems to me its looking for a .com ending of the domain... isnt it ?
0
 
RIOSmxAuthor Commented:
and lastly, the match should be, whateverthedomin/squirrelmail
0
 
RIOSmxAuthor Commented:
I tried it anyways... it gives me RewriteRule: bad argument line '^/(.*)' error
0
 
RIOSmxAuthor Commented:
nevermind error was due to line wrap
0
 
ClickCentricCommented:
RewriteEngine On
RewriteCond %{HTTP_HOST}   ^*
RewriteRule ^(www\.)?(.*)\.(.*)/squirrelmail     http://mail.$2.$3/ [L,R]
0
 
ClickCentricCommented:
Yeah, thought the above worked, but I was testing with the wrong url...it doesn't.
0
 
RIOSmxAuthor Commented:

I am getting --> RewriteCond: cannot compile regular expression '^*'
0
 
RIOSmxAuthor Commented:
RewriteEngine On
RewriteCond %{HTTP_HOST}   ^/(.*)
RewriteRule ^(www\.)?(.*)\.(.*)/squirrelmail     http://mail.$2.$3/ [L,R]

i tried the above, no luck :(
0
 
ClickCentricCommented:
RewriteEngine On
RewriteCond %{HTTP_HOST}        ^(www\.)?([a-zA-Z]*)\.([a-zA-Z]*)
RewriteRule ^(.*)/squirrelmail  http://mail.%2.%3 [L,R]


This has been tested and does work at least on one of my servers.
0
 
RIOSmxAuthor Commented:

I think that only applies to us domains ??  how about www.somedomain.com.mx ?
0
 
ClickCentricCommented:
*laughs*  Every time I think it's beat...  
0
 
ClickCentricCommented:
I THINK this might work, have no way to test it as I host no Country code tld sites and the tricks I'd normally use in php won't work...

RewriteEngine On
RewriteCond %{HTTP_HOST}        ^(www\.)?([a-zA-Z]*)\.([a-zA-Z]*)
RewriteRule ^(.*)/squirrelmail  http://mail.%2.%3 [L,R]
RewriteCond %{HTTP_HOST}        ^(www\.)?([a-zA-Z]*)\.([a-zA-Z]*)\.([a-zA-Z]*)
RewriteRule ^(.*)/squirrelmail  http://mail.%2.%3.%4 [L,R]
0
 
RIOSmxAuthor Commented:
nada :(
0
 
ClickCentricCommented:
Where exactly are you putting this?
0
 
RIOSmxAuthor Commented:

gulp...   on httpd.conf and then restart...  
0
 
ClickCentricCommented:
But I mean where in httpd.conf?  I don't think there's anywhere you can put a single instance of this to work on all domains across the server. I think it would have to be applied to each <virtualhost>.
0
 
RIOSmxAuthor Commented:

I am placing it on the last part of the file, I dont see any vhost directives there, i am using PLESK , BTW i had some results when placing RedirectMatch there..it seem to be almost working with RedirectMatch..
0
 
ClickCentricCommented:
If you're using plesk, then each account has it's own httpd.include file which you can override with a vhost.conf file.    What version of Plesk?
0
 
RIOSmxAuthor Commented:
8.0
0
 
RIOSmxAuthor Commented:

I placed it @ httpd.include it starts to work, thow, it seem it matches the first condition and strips out the .mx extension redirecting to .com only... also, cant it be done server wide :( ?
0
 
ClickCentricCommented:
I thought that might happen.  Switch the order of the RewriteCond/RewriteRule pairs.

As for doing it server-wide, I'm not sure it's possible at all, but it's even less likely to be possible with Plesk.
0
 
ClickCentricCommented:
I'm not seeing anything that indicates that it can't be used server-wide, but I'm not finding anything that says it can be either.  But the real problem is that Plesk will just overwrite it when it updates.
0
 
ahoffmannCommented:
> and lastly, the match should be, whateverthedomin/squirrelmail
this is a new requirement, posted after my suggestion

> seems to me its looking for a .com ending of the domain... isnt it ?
this is also a requirement not clearly described in the question

> it gives me RewriteRule: bad argument line '^/(.*)' error
see below ...

RewriteEngine On
RewriteCond %{REQUEST_URI} ^[/]*squirrelmail
RewriteCond %{HTTP_HOST}   ^mail\.(.*)
RewriteRule (.*)     http://mail.%1/$1/ [L,R]


If this does not work (except for compiling error), please give unique examples which FQDN should be rewritten to what, and which URL-path shouold be rewritten, and which URL are not to be rewritten.
This question is getting ambigious 'cause to change the conditions in your follow-up comments or you add new ones.
0
 
RIOSmxAuthor Commented:

Sorry, no, those where no new requirements, I was responding to "ahoffman" when he asked what was wrong with hes solution...  


it has always been the same requirement:

if someone access http://domain1/file
redirect to ---> http://mail.domain1/

Examples:

access http://www.mydomain.com/squirrelmail
redirect to --> http://webmail.mydomain.com

access http://mydomain.com/squirrelmail
redirect to --> http://webmail.mydomain.com

access http://mail.mydomain.net/squirrelmail
redirect to --> http://webmail.mydomain.net

access http://www.mydomain.com.mx/squirrelmail
redirect to --> http://webmail.mydomain.com.mx

access http://www.mydomain.org.mx/squirrelmail
redirect to --> http://webmail.mydomain.org.mx

access http://mydomain.com.mx/squirrelmail
redirect to --> http://webmail.mydomain.com.mx

I tryied your last suggesion, no luck.. :( sorry for the confusion, hope u can help
0
 
RIOSmxAuthor Commented:

of coarse mydomain can be any domain
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.