script to convert .htaccess rewrite rules to php array
authorChristian Weiske <cweiske@cweiske.de>
Thu, 3 Jul 2014 20:53:40 +0000 (22:53 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 3 Jul 2014 20:53:40 +0000 (22:53 +0200)
.gitignore
scripts/build-rewritemap.php [new file with mode: 0644]

index 53196ec..a195a9e 100644 (file)
@@ -4,5 +4,6 @@
 /build.properties
 /dist
 /lib/
+/src/gen-rewritemap.php
 /www/*.phar
 /www/*.phar.bz2
diff --git a/scripts/build-rewritemap.php b/scripts/build-rewritemap.php
new file mode 100644 (file)
index 0000000..354af7f
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+/**
+ * Convert the .htaccess rewrite rules into an array of pattern-replacement
+ * pairs.
+ * Writes src/gen-rewritemap.php
+ */
+$lines    = file(__DIR__ . '/../www/.htaccess');
+$patterns = array();
+foreach ($lines as $line) {
+    if (substr($line, 0, 11) == 'RewriteRule') {
+        list($n, $pattern, $replace) = explode(' ', rtrim($line));
+        $patterns['#' . $pattern . '#'] = $replace;
+    }
+}
+file_put_contents(
+    __DIR__ . '/../src/gen-rewritemap.php',
+    "<?php\n/* automatically created from www/.htaccess */\nreturn "
+    . var_export($patterns, true)
+    . ";\n?>\n"
+);
+?>