redirect paste url with ending slash on apache
[phorkie.git] / scripts / build-rewritemap.php
1 <?php
2 /**
3  * Convert the .htaccess rewrite rules into an array of pattern-replacement
4  * pairs.
5  * Writes src/gen-rewritemap.php
6  */
7 $lines    = file(__DIR__ . '/../www/.htaccess');
8 $patterns = array();
9 foreach ($lines as $line) {
10     if (substr($line, 0, 11) == 'RewriteRule') {
11         list($n, $pattern, $replace) = explode(' ', rtrim($line));
12         $patterns['#' . $pattern . '#'] = $replace;
13     }
14 }
15 file_put_contents(
16     __DIR__ . '/../src/gen-rewritemap.php',
17     "<?php\n/* automatically created from www/.htaccess */\nreturn "
18     . var_export($patterns, true)
19     . ";\n?>\n"
20 );
21 ?>