How to Make the M Subdomain for Mobile Websites

By Sara Williams

An increasing number of people surf the Internet using a mobile device, such as a smart phone or a tablet. Website owners can choose to either make their sites resize based on screen size or send mobile visitors to a separate version of the website that is optimized for phones. Creating an “m” subdomain for the phone-optimized version of your site is a good way to separate it from the main site, but you need to also redirect mobile visitors to the subdomain. Detecting screen size is a simple way to tell mobile browsers to redirect to the subdomain.

Make a Subdomain

Step 1

Log into the control panel for your Web hosting account. Click the “Subdomains” icon, which is often grouped with other domain-related tools.

Step 2

Type “m” in the subdomain field. Select the domain you want to add the subdomain to, using the dropdown list.

Step 3

Take note of the FTP location where your new subdomain's files will go. This information typically displays on the subdomain creation page as soon as you enter the subdomain's name. Submit the form to create your subdomain. The subdomain should go live right away, but you must upload files to it before anything will appear there.

Write the Redirect

Step 1

Open the file for your website's home page, which is usually “index.html” or “index.php.” If there are no “

” tags in that file, open the heading file, typically named “header.html” or “header.php.”

Step 2

Add “

Step 3

Write a small JavaScript to detect the screen width of the device being used to visit your website. If the screen width is less than 700 pixels, you can assume the user is visiting your website on a mobile device. In this case, redirect the user to the “m” subdomain:In the above script, change “yourdomain.com” to your own domain.

Tips & Warnings

  • The redirection script will also work with a ".mobi" domain. In that case, you would have a domain such as "mysite.mobi" instead of "m.mysite.com."