how to redirect subdomains to appropriae pages through htacess

Discussion in 'PHP' started by suman977, Oct 20, 2008.

  1. #1
    Hi webmasters!!!!


    I have incoming url = http://www.abc.mydomain.com
    and i want to point into
    destination url= http://www.mydomain.com/abc.php
    and i need to this via htaccess
    Please help
     
    suman977, Oct 20, 2008 IP
  2. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Look into mod_rewrite
     
    Kyosys, Oct 21, 2008 IP
  3. BMR777

    BMR777 Well-Known Member

    Messages:
    145
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    140
    #3
    Yeah, Kyosys is right, mod_rewrite can do this. Something like the code below will probably work if you place it in the .htaccess file in the public_html folder of your site.

    Options +FollowSymLinks
    Options +Indexes
    RewriteEngine On
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com$ [NC]
    RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.yourdomain\.com$ [NC]
    RewriteRule (.*) /$1.php [L]
    Code (markup):
    Change yourdomain and .com to match your domain, but leave the slashes in place. You'll also need the DNS redirect already set up for your site so if you type anything.yourdomain.com you get to yourdomain.com, then if that works try this code.

    BMR777
     
    BMR777, Oct 21, 2008 IP