Search code examples
.htaccesssubdomain

Mobile site m. subdomain not found


I created a mobile version of my website by adding a subdomain m.mywebsite.com, but when I type in this in the browser, I am getting "server not found" error message. When I typed mywebsite.com/mobilesitefolder, all works ok. What changes to my .htaccess file should I do to make it work?

Thats my current .htaccess content:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Solution

  • If requesting your subdomain yields a "server not found" error, that means that the DNS record is not configured correctly, or that the DNS record has not propagated to all root level DNS servers yet. Check and double check that the DNS record translates to your server (e.g. with a CNAME) and then take a coffee (or other favourite beverage) and wait. When the DNS record propagates to all root level DNS servers it should at least connect to your server.

    If your subdomain gets it's own www-root folder, e.g. /subdomains/m/ then just move your mobile site there. If your subdomain and normal domain point to the same folder, you'll need to do some .htaccess magic:

    RewriteEngine on
    
    #If host starts with m. and we are not in the m subdirectory...
    #...we internally rewrite it
    RewriteCond %{HTTP_HOST} ^m\.
    RewriteCond %{REQUEST_URI} !^/m/
    RewriteRule ^ /m%{REQUEST_URI} [L]
    
    #If the host doesn't start with m. and we are in the subdirectory...
    #...we redirect the sneaky person
    RewriteCond %{HTTP_HOST} !^m\.
    RewriteCond %{REQUEST_URI} ^/m/
    RewriteRule ^m/(.*)$ http://m.example.com/$1 [R,L]