How to Make the M Subdomain for Mobile Websites

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.

Businessman using PDA
Accommodate your mobile visitors by redirecting them to a phone-optimized website.
credit: Jupiterimages/Creatas/Getty Images

Make a Subdomain

Step

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

Step

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

Step

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

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

Add “

Step

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:

Step

Step

In the above script, change “yourdomain.com” to your own domain.