From d8a73e7951f2408c6ac1fc79b7540be0b71f25b6 Mon Sep 17 00:00:00 2001 From: Jonathan Holvey Date: Sat, 26 Aug 2017 13:02:00 +1000 Subject: [PATCH] Allow URLs to be rewritten to server root using external .htaccess MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For example, with the following directory structure, Bludit is installed in its own subdirectory: web_root ├── .htaccess └── bludit ├── bl_content ├── bl_kernel │ ... ├── .htaccess ├── index.php └── install.php However, it may be desired that Bludit's URLs are based from the web root, not /bludit: Good: http://example.com/about Bad: http://example.com/bludit/about The config file web_root/.htaccess includes the following rule to rewrite requests to web_root/bludit: RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*) bludit/$1 [NC,L,QSA] When a page is accessed, Bludit finds that the URL /about doesn't match the script path bludit/index.php, and assumes that the site's root should therefore be "/". --- bl-kernel/boot/init.php | 8 ++++++-- install.php | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bl-kernel/boot/init.php b/bl-kernel/boot/init.php index c66877f6..3411e3f1 100644 --- a/bl-kernel/boot/init.php +++ b/bl-kernel/boot/init.php @@ -209,12 +209,16 @@ elseif( empty($base) ) { $base = dirname($base); } -if($base!=DS) { +// Assume URLs are rewritten to server root if current URL doesn't start with $base +if (strpos($_SERVER['REQUEST_URI'], $base) !== 0) { + $base = '/'; +} + +if($base!=DS and strlen($base > 0)) { $base = trim($base, '/'); $base = '/'.$base.'/'; } else { - // Workaround for Windows Web Servers $base = '/'; } diff --git a/install.php b/install.php index ba5453cc..ed893f3f 100644 --- a/install.php +++ b/install.php @@ -84,12 +84,16 @@ elseif( empty($base) ) { $base = dirname($base); } -if($base!=DS) { +// Assume URLs are rewritten to server root if current URL doesn't start with $base +if (strpos($_SERVER['REQUEST_URI'], $base) !== 0) { + $base = '/'; +} + +if($base!=DS and strlen($base > 0)) { $base = trim($base, '/'); $base = '/'.$base.'/'; } else { - // Workaround for Windows Web Servers $base = '/'; }