Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing /go/ urls

  • Loading branch information...
commit 9fbe35aaebc274a49ca4bc498647c8395e9ee1e4 1 parent 51c7ca4
@jdsharp authored
Showing with 13 additions and 10 deletions.
  1. +1 −1  .htaccess
  2. +12 −9 go.php
View
2  .htaccess
@@ -1,4 +1,4 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
-RewriteRule (.*) go.php?go=$1 [L]
+RewriteRule (.*) go.php [L]
View
21 go.php
@@ -1,18 +1,21 @@
<?php
error_reporting(E_ALL);
+
function lookup($key) {
foreach (file('urls.txt') as $line_num => $line) {
- $line = split("=", $line);
- if ($line[0] == $key) {
- return $line[1];
+ $line = trim($line);
+ $eq = strpos('=', $line);
+ $k = substr($key, 0, $eq);
+ $v = substr($key, $eq+1);
+
+ if ($k == $key) {
+ return $v;
}
}
die("No URL for $key available.");
}
-if (!isSet($_GET['go'])) {
- die("Missing parameter, call via .../go/[key]");
+preg_match('/\/go\/(.*)/', $_SERVER['REQUEST_URI'], $match);
+if (!isset($match[1])) {
+ die("Missing parameter, call via /go/[key]");
}
-
-// add logging here?
-
-header('Location: ' . lookup($_GET['go']));
+header('Location: ' . lookup($match[1]));
Please sign in to comment.
Something went wrong with that request. Please try again.