2014-11-14 15:26



A customer asked me to create a subdomain with another website optimized for mobile users. I installed the latest Wordpress on this subdomain (eg This subdomain is accesible to everyone. Only the dummy text and template is available on this subdomain.

Mobile visitors should be visiting the original domain (eg until the development of the subdomain has been finished. Personally im not very proficient in using Wordpress, but I am in using weblanguages like php, mysql, js etc.

The problem that now came into existance is that some mobile browsers are automatically checking a domain for an m-subdomain. Then they automatically redirect to that subdomain. I did not know this beforehand and im looking for a quick solution. My host doesnt seem to provide an option to temporarily change the name of the subdomain. This means I have to remove the subdomain and create a new one then install wordpress again, develop the website, export the thing, remove the new subdomain, create the m subdomain again, install wordpress again, and import the developed website.

Could there be a simpler solution to this?

Edit Since there is a need to test this website on mobile phones, the access shouldnt be blocked to mobile phones.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • duanpang2751 duanpang2751 7年前

    Yes, there is a solution for this, but as Digital Chris mentioned, do not develop under production environment. Do it on localhost instead, or another domain.

    Set up a query parameter, when you first call your page.

    Let it be ?dev=123

    So, in the index php, check this and if it is set, then add a session variable to store that. Then you check, is this session variable exists. If yes, then do nothing, just develop the page. If not, then redirect everybody to the not subdomained domain.

    if (!empty($_GET["dev"]) && $_GET["dev"] == 123) {
        $_SESSION["dev"] = 123;
    if (empty($_SESSION["dev"]) || $_SESSION["dev"] != 123) {

    Of course you can set up more secure parameter name and value. This is not the most secure, way.

    An alternative way could be, if you allow only your IP(s) by checking $_SERVER["REMOTE_ADDR"]; and if it's not yours, then redirect them back to the non subdomained domain.

    点赞 评论 复制链接分享