/
ApacheGenerator.php
72 lines (65 loc) · 2.12 KB
/
ApacheGenerator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace Concrete\Core\Service\Configuration\HTTP;
use Concrete\Core\Service\Configuration\GeneratorInterface;
use Concrete\Core\Service\Rule\Rule;
use Concrete\Core\Service\Rule\RuleInterface;
use Concrete\Core\Service\Rule\Option as RuleOption;
use Exception;
class ApacheGenerator extends Generator implements GeneratorInterface
{
/**
* Initializes the instance.
*/
public function __construct()
{
parent::__construct();
$this->addRule('pretty_urls', $this->getPrettyUrlRule());
}
/**
* @return RuleInterface
*/
protected function getPrettyUrlRule()
{
$rule = new Rule(
function (Rule $rule) {
$DIR_REL = $rule->getOption('dir_rel')->getValue();
if ($DIR_REL === null) {
if (\Core::make('app')->isRunThroughCommandLineInterface()) {
throw new Exception(t('When executed from the command line, you need to specify the %s option', 'dir_rel'));
} else {
$DIR_REL = DIR_REL;
}
}
$DIR_REL = trim((string) $DIR_REL, '/');
if ($DIR_REL !== '') {
$DIR_REL = '/'.$DIR_REL;
}
$DISPATCHER_FILENAME = DISPATCHER_FILENAME;
return <<<EOT
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase $DIR_REL/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . $DISPATCHER_FILENAME [L]
</IfModule>
EOT
;
},
function () {
return (bool) \Config::get('concrete.seo.url_rewriting');
},
"# -- concrete urls start --",
"# -- concrete urls end --"
);
$option = new RuleOption(
t('Concrete path relative to website root'),
function () {
return \Core::make('app')->isRunThroughCommandLineInterface();
}
);
$rule->addOption('dir_rel', $option);
return $rule;
}
}