]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Enable 404-based rewrites for lighttpd installations in /
authorTom Adams <tom@holizz.com>
Thu, 30 Jul 2009 18:19:12 +0000 (19:19 +0100)
committerTom Adams <tom@holizz.com>
Tue, 4 Aug 2009 00:24:28 +0000 (01:24 +0100)
index.php
lighttpd.conf.example [new file with mode: 0644]

index a73983b5956f3545540dde949b333b4c83180ebf..c6776b11bbc7dff46941d57188649e90662cfce0 100644 (file)
--- a/index.php
+++ b/index.php
@@ -107,6 +107,24 @@ function checkMirror($action_obj)
 
 function main()
 {
+    // fake HTTP redirects using lighttpd's 404 redirects
+    if (strpos($_SERVER['SERVER_SOFTWARE'], 'lighttpd') !== false) {
+        $_lighty_url = $base_url.$_SERVER['REQUEST_URI'];
+        $_lighty_url = @parse_url($_lighty_url);
+
+        if ($_lighty_url['path'] != '/index.php' && $_lighty_url['path'] != '/') {
+            $_SERVER['QUERY_STRING'] = 'p='.substr($_lighty_url['path'], 1);
+            if ($_lighty_url['query'])
+                $_SERVER['QUERY_STRING'] .= '&'.$_lighty_url['query'];
+            parse_str($_lighty_url['query'], $_lighty_query);
+            foreach ($_lighty_query as $key => $val) {
+                $_GET[$key] = $_REQUEST[$key] = $val;
+            }
+            $_GET['p'] = $_REQUEST['p'] = substr($_lighty_url['path'], 1);
+        }
+    }
+    $_SERVER['REDIRECT_URL'] = preg_replace("/\?.+$/", "", $_SERVER['REQUEST_URI']);
+
     // quick check for fancy URL auto-detection support in installer.
     if (isset($_SERVER['REDIRECT_URL']) && (preg_replace("/^\/$/","",(dirname($_SERVER['REQUEST_URI']))) . '/check-fancy') === $_SERVER['REDIRECT_URL']) {
         die("Fancy URL support detection succeeded. We suggest you enable this to get fancy (pretty) URLs.");
diff --git a/lighttpd.conf.example b/lighttpd.conf.example
new file mode 100644 (file)
index 0000000..b8baafc
--- /dev/null
@@ -0,0 +1,2 @@
+# Add this line to lighttpd.conf to enable pseudo-rewrites using 404s
+server.error-handler-404 = "/index.php"