SEO, how to implement different page access for PC and mobile website

How to make a website return 404 on desktop but display normally on mobile?

Source:American Network Design
Date:2025-11-27 17:17:22
Views:21055

Many site owners have asked me about seeing special high-authority websites, such as video sites and novel sites, with excellent SEO results that they want to study. However, when accessed via desktop, they return a 404 error, but open normally on mobile devices. They ask how this is implemented. This isn't really related to SEO but rather involves programming techniques and processing methods, which I'll share today.

Technical Principle:

This operation works by identifying the request IP (some identify the visiting UA attributes) to make a judgment. To avoid affecting SEO results, when search engine spiders visit, they see one type of page, while users see a completely different set of pages. This is more of a black hat SEO approach.

Technical Code:

<?php 
$allowedIPs = array("127.0.0.1","10.0.0.1");
function getIp(){
    if(!empty($_SERVER["HTTP_CLIENT_IP"])){
        $cip = $_SERVER["HTTP_CLIENT_IP"];
    }else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
        $cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
    }else if(!empty($_SERVER["REMOTE_ADDR"])){
        $cip = $_SERVER["REMOTE_ADDR"];
    }else{
        $cip = '';
    }
    preg_match("/[\d\.]{7,15}/",$cip,$cips);
    $cip = isset($cips[0])?$cips[0]:'unknown';
    unset($cips);
    return $cip;
}
function isPc(){
    $userAgent = $_SERVER['HTTP_USER_AGENT'];
    $mobileKeywords= array('iPhone', 'Android', 'Windows Phone');
    foreach ($mobileKeywords as $keyword) {
        if(stripos($userAgent, $keyword) !== false){
            return false;
        }
        return true;
    }
}
if (isPc() && !in_array(getIp(), $allowedIPs)){
    header("HTTP/1.0 404 Not Found");
    exit();
}
?>

Above is a PHP code snippet that implements this functionality. Replace "127.0.0.1" and "10.0.0.1" with the search engine spider IPs, name the file index.php, and place it in the website's root directory. You can try similar methods by identifying UA (user-agent) attributes for making judgments.

This article is for technical learning purposes only and should not be used for illegal purposes. Zhile Network does not provide black hat SEO or any technical support for sensitive gray industries. Please don't inquire about such services.

Related Tags:
Recommended Reading