Browse Source

Add pretty URL support

tags/1.0
Skylar Ittner 1 year ago
parent
commit
a94df59ac5
3 changed files with 34 additions and 7 deletions
  1. 14
    2
      lib/themefunctions.php
  2. 3
    0
      settings.template.php
  3. 17
    5
      webroot.htaccess

+ 14
- 2
lib/themefunctions.php View File

@@ -59,7 +59,11 @@ function get_page_clean_url($echo = true, $slug = null) {
59 59
     if ($slug == null) {
60 60
         $slug = get_page_slug(false);
61 61
     }
62
-    $url = formatsiteurl(get_site_url(false)) . "index.php?id=$slug";
62
+    if (PRETTY_URLS) {
63
+        $url = formatsiteurl(get_site_url(false)) . "$slug";
64
+    } else {
65
+        $url = formatsiteurl(get_site_url(false)) . "index.php?id=$slug";
66
+    }
63 67
     if ($echo) {
64 68
         echo $url;
65 69
     } else {
@@ -91,7 +95,15 @@ function get_page_url($echo = true, $slug = null) {
91 95
     if (isset($_GET['siteid'])) {
92 96
         $siteid = "&siteid=" . preg_replace("/[^0-9]/", '', $_GET['siteid']);
93 97
     }
94
-    $url = formatsiteurl(get_site_url(false)) . "index.php?id=$slug$edit$theme$template$color$siteid";
98
+    $args = "$edit$theme$template$color$siteid";
99
+    if (PRETTY_URLS) {
100
+        if ($args != "") {
101
+            $args = "?$args";
102
+        }
103
+        $url = formatsiteurl(get_site_url(false)) . "$slug$args";
104
+    } else {
105
+        $url = formatsiteurl(get_site_url(false)) . "index.php?id=$slug$args";
106
+    }
95 107
     if ($echo) {
96 108
         echo $url;
97 109
     } else {

+ 3
- 0
settings.template.php View File

@@ -37,6 +37,9 @@ define('URL', '/sitewriter');
37 37
 // Folder for public files
38 38
 define('FILE_UPLOAD_PATH', __DIR__ . '/public/files');
39 39
 
40
+// Use pretty URLs (requires correct web server configuration)
41
+define('PRETTY_URLS', false);
42
+
40 43
 // Location of MaxMind GeoIP database
41 44
 //
42 45
 // I'll just leave this here:

+ 17
- 5
webroot.htaccess View File

@@ -1,9 +1,21 @@
1 1
 RewriteEngine On
2 2
 RewriteBase /
3 3
 
4
-RewriteCond %{REQUEST_FILENAME} !-d [OR]
5
-RewriteCond %{REQUEST_URI} ^/$
6
-RewriteCond %{REQUEST_FILENAME} !-f
7
-RewriteCond %{REQUEST_FILENAME} !-l
8 4
 
9
-RewriteRule (.*) /sitewriter/public/$1 [L]
5
+# Everything else
6
+RewriteCond %{REQUEST_FILENAME} -f [OR]
7
+RewriteCond %{REQUEST_FILENAME} -d
8
+RewriteRule ^(.+) - [PT,L]
9
+
10
+# Webroot
11
+RewriteRule ^/$ /sitewriter/public [L]
12
+
13
+# Other URLs (assets, etc)
14
+RewriteCond %{DOCUMENT_ROOT}/sitewriter/public%{REQUEST_URI} -d [OR]
15
+RewriteCond %{DOCUMENT_ROOT}/sitewriter/public%{REQUEST_URI} -f
16
+RewriteRule ^(.*)$ /sitewriter/public/$1 [L]
17
+
18
+# Pretty URLs
19
+RewriteCond %{DOCUMENT_ROOT}/sitewriter/public%{REQUEST_URI} !-d [OR]
20
+RewriteCond %{DOCUMENT_ROOT}/sitewriter/public%{REQUEST_URI} !-f
21
+RewriteRule ^(.*)$ /sitewriter/public/index.php?id=$1 [L,QSA]

Loading…
Cancel
Save