Added robots.txt plugin
Automatically generates the content, including the correct link to the sitemap.
This commit is contained in:
parent
eaca96fd6b
commit
91395db9c4
5 changed files with 31 additions and 16 deletions
|
@ -5,16 +5,6 @@ location ~ ^/Themes/[^/]+/Assets/ {
|
|||
}
|
||||
}
|
||||
|
||||
location /robots.txt {
|
||||
# Allow access to the robots.txt file
|
||||
try_files $uri =204;
|
||||
}
|
||||
|
||||
location /sitemap.xml {
|
||||
# Allow access to the sitemap.xml file
|
||||
try_files $uri =204;
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php?$args;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,4 @@ CGIPassAuth On
|
|||
RewriteCond %{REQUEST_FILENAME} -f
|
||||
RewriteRule ^Themes/[^/]+/Assets/.+$ - [L]
|
||||
|
||||
# Allow access to the robots.txt file
|
||||
RewriteRule ^robots\.txt$ - [L]
|
||||
|
||||
RewriteRule ^(.+)$ index.php [L,QSA]
|
||||
|
|
25
src/Plugins/Robotstxt/RobotstxtPlugin.php
Normal file
25
src/Plugins/Robotstxt/RobotstxtPlugin.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
use AntCMS\AntPlugin;
|
||||
use AntCMS\AntConfig;
|
||||
use AntCMS\AntTools;
|
||||
|
||||
class RobotstxtPlugin extends AntPlugin
|
||||
{
|
||||
public function handlePluginRoute(array $route)
|
||||
{
|
||||
$protocol = AntConfig::currentConfig('forceHTTPS') ? 'https' : 'http';
|
||||
$baseURL = AntConfig::currentConfig('baseURL');
|
||||
|
||||
$robotstxt = 'User-agent: *' . "\n";
|
||||
$robotstxt.= 'Disallow: /plugin/' . "\n";
|
||||
$robotstxt.= 'Sitemap: ' . $protocol . '://' . AntTools::repairURL($baseURL . '/sitemap.xml' . "\n");
|
||||
header("Content-Type: text/plain");
|
||||
echo $robotstxt;
|
||||
exit;
|
||||
}
|
||||
public function getName()
|
||||
{
|
||||
return 'Robotstxt';
|
||||
}
|
||||
}
|
|
@ -59,6 +59,11 @@ if($segments[0] == 'sitemap.xml'){
|
|||
$segments[1] = 'sitemap';
|
||||
}
|
||||
|
||||
if ($segments[0] == 'robots.txt') {
|
||||
$segments[0] = 'plugin';
|
||||
$segments[1] = 'robotstxt';
|
||||
}
|
||||
|
||||
if ($segments[0] === 'plugin') {
|
||||
$pluginName = $segments[1];
|
||||
$pluginLoader = new AntPluginLoader();
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
User-agent: *
|
||||
Disallow: /plugin/
|
Loading…
Reference in a new issue