From a94df59ac5a1e9c8608b5c856f65390821540e52 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Fri, 4 May 2018 23:47:46 -0600 Subject: [PATCH] Add pretty URL support --- lib/themefunctions.php | 16 ++++++++++++++-- settings.template.php | 3 +++ webroot.htaccess | 22 +++++++++++++++++----- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/lib/themefunctions.php b/lib/themefunctions.php index dc53867..0042876 100644 --- a/lib/themefunctions.php +++ b/lib/themefunctions.php @@ -59,7 +59,11 @@ function get_page_clean_url($echo = true, $slug = null) { if ($slug == null) { $slug = get_page_slug(false); } - $url = formatsiteurl(get_site_url(false)) . "index.php?id=$slug"; + if (PRETTY_URLS) { + $url = formatsiteurl(get_site_url(false)) . "$slug"; + } else { + $url = formatsiteurl(get_site_url(false)) . "index.php?id=$slug"; + } if ($echo) { echo $url; } else { @@ -91,7 +95,15 @@ function get_page_url($echo = true, $slug = null) { if (isset($_GET['siteid'])) { $siteid = "&siteid=" . preg_replace("/[^0-9]/", '', $_GET['siteid']); } - $url = formatsiteurl(get_site_url(false)) . "index.php?id=$slug$edit$theme$template$color$siteid"; + $args = "$edit$theme$template$color$siteid"; + if (PRETTY_URLS) { + if ($args != "") { + $args = "?$args"; + } + $url = formatsiteurl(get_site_url(false)) . "$slug$args"; + } else { + $url = formatsiteurl(get_site_url(false)) . "index.php?id=$slug$args"; + } if ($echo) { echo $url; } else { diff --git a/settings.template.php b/settings.template.php index 34e86ca..8f9e40a 100644 --- a/settings.template.php +++ b/settings.template.php @@ -37,6 +37,9 @@ define('URL', '/sitewriter'); // Folder for public files define('FILE_UPLOAD_PATH', __DIR__ . '/public/files'); +// Use pretty URLs (requires correct web server configuration) +define('PRETTY_URLS', false); + // Location of MaxMind GeoIP database // // I'll just leave this here: diff --git a/webroot.htaccess b/webroot.htaccess index 6261c03..ce34059 100644 --- a/webroot.htaccess +++ b/webroot.htaccess @@ -1,9 +1,21 @@ RewriteEngine On RewriteBase / -RewriteCond %{REQUEST_FILENAME} !-d [OR] -RewriteCond %{REQUEST_URI} ^/$ -RewriteCond %{REQUEST_FILENAME} !-f -RewriteCond %{REQUEST_FILENAME} !-l -RewriteRule (.*) /sitewriter/public/$1 [L] +# Everything else +RewriteCond %{REQUEST_FILENAME} -f [OR] +RewriteCond %{REQUEST_FILENAME} -d +RewriteRule ^(.+) - [PT,L] + +# Webroot +RewriteRule ^/$ /sitewriter/public [L] + +# Other URLs (assets, etc) +RewriteCond %{DOCUMENT_ROOT}/sitewriter/public%{REQUEST_URI} -d [OR] +RewriteCond %{DOCUMENT_ROOT}/sitewriter/public%{REQUEST_URI} -f +RewriteRule ^(.*)$ /sitewriter/public/$1 [L] + +# Pretty URLs +RewriteCond %{DOCUMENT_ROOT}/sitewriter/public%{REQUEST_URI} !-d [OR] +RewriteCond %{DOCUMENT_ROOT}/sitewriter/public%{REQUEST_URI} !-f +RewriteRule ^(.*)$ /sitewriter/public/index.php?id=$1 [L,QSA] \ No newline at end of file