dongzhan7909 2014-11-14 15:26
浏览 58
已采纳

阻止手机访问子域名m

A customer asked me to create a subdomain with another website optimized for mobile users. I installed the latest Wordpress on this subdomain (eg m.domain.com). 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 www.domain.com) 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.

  • 写回答

1条回答 默认 最新

  • duanpang2751 2014-11-14 15:35
    关注

    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.

    session_start();
    if (!empty($_GET["dev"]) && $_GET["dev"] == 123) {
        $_SESSION["dev"] = 123;
    }
    
    if (empty($_SESSION["dev"]) || $_SESSION["dev"] != 123) {
        header('Location: http://www.domain.com');
        die();
    }
    

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 C# datagridview 栏位进度