Skip to content
Snippets Groups Projects
Commit 169e41cd authored by Yousef Bajawi's avatar Yousef Bajawi Committed by Rajab Natshah
Browse files

Issue #2853988 by josebc: Add option to rewrite robots.txt on staging enviroments

parent b447dd4a
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,11 @@ ...@@ -28,6 +28,11 @@
"config": { "config": {
"bin-dir": "bin/" "bin-dir": "bin/"
}, },
"autoload": {
"classmap": [
"src/composer/ScriptHandler.php"
]
},
"repositories": [ "repositories": [
{ {
"type": "composer", "type": "composer",
...@@ -68,6 +73,9 @@ ...@@ -68,6 +73,9 @@
"post-update-cmd": [ "post-update-cmd": [
"./bin/phing push" "./bin/phing push"
], ],
"post-drupal-scaffold-cmd": [
"Varbase\\composer\\ScriptHandler::postDrupalScaffoldProcedure"
],
"drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold" "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold"
}, },
"extra": { "extra": {
...@@ -201,4 +209,4 @@ ...@@ -201,4 +209,4 @@
"drupal/varbase_heroslider_media": "4.0-alpha4", "drupal/varbase_heroslider_media": "4.0-alpha4",
"drupal/varbase_carousels": "4.0-alpha2" "drupal/varbase_carousels": "4.0-alpha2"
} }
} }
\ No newline at end of file
...@@ -6,4 +6,5 @@ projects[drupal][type] = "core" ...@@ -6,4 +6,5 @@ projects[drupal][type] = "core"
projects[drupal][version] = "8.2.6" projects[drupal][version] = "8.2.6"
;; Issue #2479377: content_translation_page_attachments() should check for a canonical link before generating a URL to it ;; Issue #2479377: content_translation_page_attachments() should check for a canonical link before generating a URL to it
projects[drupal][patch][] = https://www.drupal.org/files/issues/content-translation-canonical-2479377-30.patch projects[drupal][patch][] = https://www.drupal.org/files/issues/content-translation-canonical-2479377-30.patch
projects[drupal][patch][] = https://www.drupal.org/files/issues/drupal_8-allow_stg_robots-2853988-2.patch
# This will rewrite robots.txt on non-production environments to robots-staging.txt to disallow robots from indexing.
# Example: http://stg.example.com/robots.txt will be rewritten to http://stg.example.com/robots-staging.txt
# Uncomment the following two lines and change www.example.com to your production URL:
# RewriteCond %{HTTP_HOST} !^www.example.com$
# RewriteRule ^robots.txt$ robots-staging.txt [L]
User-agent: *
Disallow: /
\ No newline at end of file
<?php
/**
* @file
* Contains \Varbase\composer\ScriptHandler.
*/
namespace Varbase\composer;
use Composer\EventDispatcher\Event;
class ScriptHandler {
/**
* Get the Drupal root directory.
*
* @param type $project_root
* @return type
*/
protected static function getDrupalRoot($project_root) {
return $project_root . '/docroot';
}
/**
* Post Drupal Scaffold Procedure.
*
* @param \Composer\EventDispatcher\Event $event
* The script event.
*/
public static function postDrupalScaffoldProcedure(Event $event) {
//Create staging robots file
copy(getcwd() . '/src/assets/robots-staging.txt', static::getDrupalRoot(getcwd()) . '/robots-staging.txt');
//Alter .htaccess file
$htaccess_path = static::getDrupalRoot(getcwd()) . '/.htaccess';
$htaccess_lines = file($htaccess_path);
$lines = [];
foreach ($htaccess_lines as $line) {
$lines[] = $line;
if(strpos($line, "RewriteEngine on") !== FALSE) {
$lines = array_merge($lines, file(getcwd() . '/src/assets/htaccess_extra'));
}
}
file_put_contents($htaccess_path, $lines);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment