yf_robotstxt user module

Fileplugins/common/modules/yf_robotstxt.class.php
Usemodule('robotstxt'), URL ?object=robotstxt

Public properties

PropertyDefaultDescription
None declared in this class.

Public methods 1

show

public function show()
    public function show()
    {
        header('Content-Type: text/plain', $replace = true);
        $host = ($_GET['host'] ?? null) ?: ($_SERVER['HTTP_HOST'] ?? null); // $_GET['host'] just for debug purposes
        $prod_hosts = main()->PRODUCTION_DOMAIN ?: [];
        if (is_string($prod_hosts)) {
            $prod_hosts = [$prod_hosts];
        }
        if ( ! main()->is_dev() && in_array($host, $prod_hosts)) {
            // Allow indexing of whole website = production
            $out = 'User-agent: *' . PHP_EOL . 'Disallow:';
        } else {
            // Deny indexing of whole website - useful for dev domains
            $out = 'User-agent: *' . PHP_EOL . 'Disallow: /';
        }
        echo $out;
        exit;
    }