#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    uk
    Posts
    100
    Rep Power
    11

    Subdomain Rewrite *.example.com to this.example.com


    I would like my site to direct all traffic from www.example.com and example.com or anythingelse.example.com to this.example.com This is what I have in my .htaccess file which is located in /www/example.com/public_html directory

    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ http://this.example.com/ [R=301,L]
    It works when I visit this.example.com but when I visit http://example.com it redirects me to example.com/public_html and www.example.com doesn't redirect at all! However this.example.com works. This is my virtual host setting:

    Code:
    <VirtualHost 12.34.56.78:80>
     ServerAdmin webmaster@example.com
     ServerName example.com
     ServerAlias this.example.com
     ServerAlias www.example.com
     DocumentRoot /srv/www/example.com/public_html/
     ErrorLog /srv/www/example.com/logs/error.log
     CustomLog /srv/www/example.com/logs/access.log combined
    </VirtualHost>
    I've noticed in my error log when I visit: example.com it says "File does not exist: /srv/www/example.com/public_html/public_html"

    Thanks!
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,185
    Rep Power
    9398
    Try something more like
    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !this.example.com
    RewriteRule ^ http://this.example.com%{REQUEST_URI} [L]

    Comments on this post

    • xylar agrees : Thanks. Works a treat :)

IMN logo majestic logo threadwatch logo seochat tools logo