浏览代码

Drop the "index" part of URLs

Closes #347. Thanks @Robby-
Daniel Rudolf 9 年之前
父节点
当前提交
1b3ef7516d
共有 1 个文件被更改,包括 11 次插入2 次删除
  1. 11 2
      lib/Pico.php

+ 11 - 2
lib/Pico.php

@@ -1387,9 +1387,18 @@ class Pico
                 . (is_object($queryData) ? get_class($queryData) : gettype($queryData)) . ' given'
             );
         }
+
+        // drop "index"
+        if ($page === 'index') {
+            $page = '';
+        } elseif (($pagePathLength = strrpos($page, '/')) !== false) {
+            if (substr($page, $pagePathLength + 1) === 'index') {
+                $page = substr($page, 0, $pagePathLength);
+            }
+        }
+
         if (!empty($queryData)) {
-            $page = !empty($page) ? $page : 'index';
-            $queryData = $this->isUrlRewritingEnabled() ? '?' . $queryData : '&' . $queryData;
+            $queryData = ($this->isUrlRewritingEnabled() || empty($page)) ? '?' . $queryData : '&' . $queryData;
         }
 
         if (empty($page)) {