Last active
August 29, 2015 14:16
-
-
Save isaacrankin/8176e6bb44b023d349e9 to your computer and use it in GitHub Desktop.
Disable robots for staging site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use PHP to output robots.txt to avoid accidentally indexing staging sites | |
RewriteRule ^robots\.txt$ robots.php [NC,L] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(0); | |
// Default robots - crawl everything | |
$robotsTxt = "# www.robotstxt.org/ | |
\r\n | |
# Allow crawling of all content\r\n | |
User-agent: *"; | |
// If on a staging site prevent indexing, add more domains here if needed | |
if(strpos($_SERVER['SERVER_NAME'], 'staging.com') !== false){ | |
$robotsTxt = "User-agent: * \r\nDisallow: /"; | |
}else{ | |
// read static robots.txt template | |
$robotsTxt = @file_get_contents('robots.txt'); | |
} | |
header('Content-Type:text/plain'); | |
echo $robotsTxt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# www.robotstxt.org/ | |
# Allow crawling of all content | |
User-agent: * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment