]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Remove script name from URL if it's index.php
authorSébastien SAUVAGE <sebsauvage@sebsauvage.net>
Wed, 27 Feb 2013 15:52:32 +0000 (16:52 +0100)
committerSébastien SAUVAGE <sebsauvage@sebsauvage.net>
Wed, 27 Feb 2013 15:52:32 +0000 (16:52 +0100)
(for better looking URLs, eg. http://mysite.com/shaarli/?abcde instead
of http://mysite.com/shaarli/index.php?abcde)

index.php

index b7ed370dcad9cb11845dbca098e317d79476cfd1..0590b2f64f46deb343c44d1c8f77ded86f49b41a 100644 (file)
--- a/index.php
+++ b/index.php
@@ -427,7 +427,11 @@ function serverUrl()
 // (eg. http://sebsauvage.net/links/)
 function indexUrl()
 {
-    return serverUrl() . ($_SERVER["SCRIPT_NAME"] == '/index.php' ? '/' : $_SERVER["SCRIPT_NAME"]);
+    $scriptname = $_SERVER["SCRIPT_NAME"];
+    // If the script is named 'index.php', we remove it (for better looking URLs,
+    // eg. http://mysite.com/shaarli/?abcde instead of http://mysite.com/shaarli/index.php?abcde)
+    if (endswith($scriptname,'index.php')) $scriptname = substr($scriptname,0,strlen($scriptname)-9);
+    return serverUrl() . $scriptname;
 }
 
 // Returns the absolute URL of current script, WITH the query.