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,

    I have viewing the city names in my website like the following structure -
    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-

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

    TheVisitors Greenhorn

    Likes Received:
    Best Answers:
    Trophy Points:
    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]
    Code (ApacheConf):
    With your DNS provider, configure the wildcard.

    *.mydomain.com. IN A

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