1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: How to redirect a subdomain to a port in Apache?

Discussion in 'Web Design & Development' started by Soundy, Dec 11, 2009.

Thread Status:
Not open for further replies.
Advertisement
  1. Soundy

    Soundy Thread Starter

    Joined:
    Feb 17, 2006
    Messages:
    1,834
    Quite simply: I'm running mail and webserver on the same system... the mailserver has its own webmail interface on port xxxx. I want, for example, 'http://webmail.mydomain.com' to redirect to "http://mydomain.com:xxxx". How would I do this in Apache 2.2?
     
  2. ehymel

    ehymel

    Joined:
    Aug 12, 2007
    Messages:
    695
    In the apache config file (or within one of the conf.d/*.conf files, use the Redirect command.

    Code:
    Redirect permanent / http://mydomain.com:xxxx
    The 'permanent' designation is optional.

    Another good solution if you want *ALL* requests for a page within the the default port 80 request to be redirected to the same request within another port, something like this could be used:

    Code:
    RedirectMatch permanent /(.*) http://mydomain.com:xxxx/$1
    Hope this helps.
     
  3. Soundy

    Soundy Thread Starter

    Joined:
    Feb 17, 2006
    Messages:
    1,834
    Hmmm that's redirecting EVERYTHING to port xxxx - I don't want mydomain.com or www.mydomain.com to redirect, just webmail.mydomain.com
     
  4. ehymel

    ehymel

    Joined:
    Aug 12, 2007
    Messages:
    695
    I guess I should have been more specific.

    The Redirect statements should go within your <VirtualHost> section for the subdomain you are wanting to redirect.

    For example, I use the following section to redirect all port 80 requests to a SSL connection on 2 different web-based email domains that I maintain, along with a snippet to show how I use a permanent redirect. Hopefully this will show some examples of how I use these:

    Code:
    <VirtualHost *:80>
        ServerName mail.e-medico.com
        ServerAlias group.e-medico.com
        RedirectPermanent / https://group.e-medico.com/
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerName mail.setexonc.com
        RedirectPermanent / https://mail.setexonc.com/
    </VirtualHost>
    
    <VirtualHost *:80>
        DocumentRoot /var/www/sites.clients/setexonc.com/www
        ServerName setexonc.com
        ServerAlias www.setexonc.com
    
        RedirectMatch /treatment/(.*).htm$ http://www.rtanswers.org/treatment/$1.htm
        RedirectMatch /index.html /
        RedirectPermanent /mail https://mail.setexonc.com/
        ErrorDocument 404 /error.php
        <Directory /var/www/sites.clients/setexonc.com/>
            allow from all
            order allow,deny
        </Directory>
    </VirtualHost>
    
     
  5. Soundy

    Soundy Thread Starter

    Joined:
    Feb 17, 2006
    Messages:
    1,834
    Oooooh I see, got it, thanks.

    Works perfectly now!
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/884718