1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

.htaccess Wildcard Subdomains

Discussion in 'Apache' started by falconlink, Jul 11, 2015.

  1. #1
    Hi everybody,
    SEMrush
    I have viewing the city names in my website like the following structure -
    www.mydomain.com/state/city/
    Here is the ,htaccess code-
    RewriteRule ^([^/]*)/([^/]*)/$ city.php?state=$1&city=$2 [NC]

    But actually, I'm looking for to use wildcard subdomains that will rebuild the city names like the following structure-
    city.mydomain.com/state/

    Can you help me? I just need the htaccess rewrite code.
     
    falconlink, Jul 11, 2015 IP
    SEMrush
  2. TheVisitors

    TheVisitors Greenhorn

    Messages:
    72
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #2
    Try this, but I'm not sure if this is something you can achieve with htaccess alone.
    <IfModule mod_rewrite.c>
       Options +FollowSymLinks
       Options +Indexes
       RewriteEngine On
       RewriteBase /
       RewriteCond %{HTTP_HOST} !www.mydomain.com$ [NC]
       RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).mydomain.com [NC]
       RewriteRule (.*) mydomain.com/city.php?state=$1&city=$2 [NC] [L]
    </IfModule>
    Code (ApacheConf):
    With your DNS provider, configure the wildcard.

    *.mydomain.com. IN A 1.2.3.4

    (Obviously adjust the DNS to your needs)
     
    TheVisitors, Jul 16, 2015 IP