Skip to content

Commit

Permalink
Update robots.txt, add ROBOTS_DISALLOWED and extra-robots.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
naresh-kumar-babu committed Aug 1, 2024
1 parent 9657fb3 commit e92dd3f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions _sources/configs/robots.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
ini_set( 'display_errors', 0 );
error_reporting( 0 );

echo "# It generated by the robots.php file\n";

header( 'Content-Type: text/plain' );

$robotsDisallowed = getenv( 'ROBOTS_DISALLOWED' );
if ( !empty( $robotsDisallowed ) && in_array( strtolower($robotsDisallowed), [ 'true', '1' ] ) ) {
die( "User-agent: *\nDisallow: /\n" );
}

$enableSitemapEnv = getenv( 'MW_ENABLE_SITEMAP_GENERATOR');
// match the value check to the isTrue function at _sources/scripts/functions.sh
if ( !empty( $enableSitemapEnv ) && in_array( $enableSitemapEnv, [ 'true', 'True', 'TRUE', '1' ] ) ) {
Expand All @@ -25,3 +32,12 @@
}

readfile( 'robots-main.txt' );

// If the file `extra-robots.txt` is created under the name
// `/var/www/mediawiki/extra-robots.txt` then its contents get appended to the
// default `robots.txt` - see MW-312
if ( is_readable( 'extra-robots.txt' ) ) {
// Extra line to separate the files so that rules don't combine
echo "\n";
readfile( 'extra-robots.txt' );
}

0 comments on commit e92dd3f

Please sign in to comment.