Server-wide redirect of domain.tld/webmail to webmail.domain.tld

Posted on 2010-04-05
Medium Priority
Last Modified: 2012-05-09

We need to set up a server-wide redirect rule in httpd/conf.d but I'm not sure of the exact syntax. There are hundreds of domains, a mixture of .com, .co.uk, .net etc.

Basically, anybody accessing domain.tld/webmail should be redirected to webmail.domain.tld.


-> http://webmail.domain1.com

-> http://webmail.domain1.com

-> http://webmail.domain2.co.uk

-> http://webmail.domain2.co.uk

The reason for this is a change of hosting provider. The old host supplied email via /webmail, whereas the new host uses webmail.domain.com.

A 301 redirect would be ideal, but it must be server-wide, not htaccess.
Question by:redcarrot
  • 3
LVL 43

Assisted Solution

by:David S.
David S. earned 1000 total points
ID: 29864193
Try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^(www\.)?([a-zA-Z0-9.-]+)$
RewriteRule ^/webmail    http://webmail.%2/ [L,R=301]

Open in new window


Author Comment

ID: 29883368
I have tried the above suggestion, but it didn't work.

Copy the above code in and save.
Restart Apache.

The code is having no effect.
LVL 51

Assisted Solution

by:Steve Bink
Steve Bink earned 1000 total points
ID: 29885550
Turn on your rewriting log and post the results of a single attempt.

Accepted Solution

redcarrot earned 0 total points
ID: 30235952
Problem solved :

1) Create a new file: /etc/httpd/conf.d

Alias /webmail /var/www/html/webmail

<Directory "/var/www/html/webmail/">
AllowOverride All

2) Create another new file: /var/www/html/webmail/index.php

<?php header("Location:http://webmail." . str_replace("www.", "", $_SERVER['HTTP_HOST'])); ?>

3) That's it. Restart Apache, and now anydomain.com/webmail redirects to webmail.anydomain.com.

Author Comment

ID: 30236479

1) Create a new file: /etc/httpd/conf.d

should read

1) Create a new file: /etc/httpd/conf.d/webmail.conf

How do I edit my post?

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

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.

Join & Write a Comment

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Suggested Courses

597 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