htaccess rewrite rule for wildccard Domain?

Discussion in 'Apache' started by Ferturion, Jun 17, 2010.

  1. #1
    Hello,
    i need some help with my .htaccess. I setup a *.domain.com subdomain and now i can access the page with any word before it. But i want to rewrite:

    http://www.sub.domain.com to
    http://sub.domain.com

    If its a single subdomain redirecting is no problem but i don't know how to setup my htacces to achieve that for any written word before the domain.

    (example: sdfsdf.domain.com / game.domain.com / fun.domain.com .... )

    Thanks for the help!
     
    Ferturion, Jun 17, 2010 IP
  2. bvsonline

    bvsonline Peon

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,

    Try the following format.
    ==============
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com$ [NC]
    RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.yourdomain\.com$ [NC]
    RewriteRule (.*) http://yourdomain.com/$1 [R=301,L]
    ===============
     
    bvsonline, Jun 18, 2010 IP