The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Subdomains with .htaccess

Discussion in 'General Discussion' started by ronpul, Feb 19, 2006.

  1. ronpul

    ronpul Registered

    Joined:
    Feb 15, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Hi,
    I wanted to make subdomains without CPanel using .htaccess .
    What i want is to treat a subdomain like http://try.example.com to http://www.example.com/try/ .
    I dont want to use CPanel in this.
    I tried a lot but no result.

    Here is the code that i tried:

    Code:
    RewriteEngine on  
    RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$  
    RewriteCond %{HTTP_HOST} !^www\.example\.com$  
    RewriteRule (.*) http://www.example.com/%1$1 [P]
    
    My present Host is using CPanel.

    Pls reply and help me out.

    Thanks and have a good day.
     
  2. Murtaza_t

    Murtaza_t Well-Known Member

    Joined:
    Jan 24, 2005
    Messages:
    476
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Earth
    cPanel Access Level:
    Website Owner
    Try this out..

    Code:
    # Rewrite subdomain requests to subdirectories except for www.example.com 
    RewriteEngine On 
    RewriteCond %{REQUEST_URI} !^/sd_ 
    RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC] 
    RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com 
    RewriteRule (.*) /sd_%1/$1 [L] 
    # 
    # Redirect direct user-agent requests for www.example.com/sd_<subdomain>/<page> to http://<subdomain>.example.com/<page> 
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /sd_(.+)\ HTTP/ 
    RewriteRule ^sd_([^/]+)/(.*)$ http://$1.example.com/$2 [R=301,L]
    Also please make sure that UseCanonicalName is set to OFF in the virtual host entry of your domain in httpd.conf
     
Loading...

Share This Page