Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2008

    Question Help writing .htaccess file with Subdomain Redirects?=

    Hi there,

    We are trying to write a .htaccess file that does the following:

    If a user types either "" or "" they will be redirected to

    I've done quite a bit of researching on Google and can't seem to find anything, which leads me to believe that it is not possible to achieve this with .htaccess, but I would greatly appreciate any help if anyone knows how to do it! Unfortunately, the hosting account we need to do this on has a crippled control panel because it is currently hosted with CBeyond... (they don't use cpanel, it is something that was built in house ) Therefore, our only option we be to use a .htaccess file, or something similar.

    Thanks again for any suggestions!

  2. #2
    Join Date
    Mar 2009
    RewriteCond %{HTTP_HOST} !^ [NC]
    RewriteRule ^(.*)$ [L,R=301]

    possibly? (untested, off the top of my head)

  3. #3
    Join Date
    Aug 2008
    Hmm, that still produces a "server can not be found" error when I try to go to the subdomain. Is it possible that the web host is somehow blocking my ability to do redirects through htaccess?

    I have mod_rewrite turned on (or in the .htaccess file, at least)...

  4. #4
    Join Date
    Feb 2005
    Quote Originally Posted by techietype View Post
    Hmm, that still produces a "server can not be found" error when I try to go to the subdomain.
    That's a dns error - nothing to do with your .htaccess. You need to find some way to add the subdomain record (or perhaps a wildcard subdomain) to your dns records. If the host's panel doesn't allow you to create a subdomain then you'll need to either submit a ticket and ask them to do it manually or use a different dns provider (your registrar / dnsmadeeasy / zoneedit etc).

    Without using the control panel there's also another step you'll need to get this to work - the virtualhost for your site must be configured to host the subdomain, otherwise the webserver won't associate the subdomain with your account, and won't find your .htaccess. If you're on a dedicated IP this might happen automatically but generally it's only set up by the control panel when you add a subdomain.

    TBH, if you need subdomains and can't simply add them through the control panel, you might be better off just looking for another host.

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  5. #5
    Join Date
    Sep 2009
    Put this in your apache config file:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
    RewriteRule ^(.*)$ http://domaincom/$1 [L,R=301]

    For more infor, check this ->

    and this ->|Virtual Private Servers|Dedicated Servers|
    Managed Hosting Solution|24/7/365 Support
    Datacentar and servers location: Holland, Europe

  6. #6
    Join Date
    Nov 2009
    Create a .htaccess file in web root with the following..

    Change the obvious such as folder, yoursite and .com if it's anything other than .com


    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^$
    RewriteRule ^(.*)$ [L,R=301]

Similar Threads

  1. htaccess redirects with variables
    By BELLonline in forum Programming Discussion
    Replies: 8
    Last Post: 04-22-2008, 09:05 AM
  2. Making subdomain redirects in DirectAdmin
    By kenfused in forum Hosting Software and Control Panels
    Replies: 1
    Last Post: 07-04-2005, 01:14 PM
  3. File type redirects with htaccess?
    By emills01 in forum Web Design and Content
    Replies: 5
    Last Post: 04-20-2005, 11:34 PM
  4. subdomain redirects to outside servers.
    By Homeblock in forum Hosting Security and Technology
    Replies: 2
    Last Post: 08-19-2004, 11:02 PM
  5. writing to a .htaccess & .htpasswd file
    By WreckRman2 in forum Dedicated Server
    Replies: 5
    Last Post: 09-03-2001, 04:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts