Permalink
Browse files

short links routing fixed.

  • Loading branch information...
1 parent 59322c2 commit c7ad685579f1583d28735047e828339ca0a718fc @bfontaine bfontaine committed Feb 2, 2013
Showing with 27 additions and 2 deletions.
  1. +5 −1 .htaccess
  2. +21 −0 controllers/shortlinks.php
  3. +1 −1 index.php
View
@@ -27,7 +27,11 @@ RewriteCond %{SCRIPT_FILENAME} !-f
# test string is a valid directory
RewriteCond %{SCRIPT_FILENAME} !-d
-RewriteRule ^(.*)$ index.php?uri=/$1 [NC,L,QSA]
+# For shortened links, using s.infop7.org/<something>
+RewriteRule ^_shortlinks/(.*)$ _shortlinks/index.php?uri=/$1 [NC,L,QSA]
+
+RewriteCond %{HTTP_HOST} !^s. [NC]
+RewriteRule ^(.*)$ index.php?uri=/$1 [NC,L,QSA]
# with QSA flag (query string append),
# forces the rewrite engine to append a query string part of the
# substitution string to the existing string, instead of replacing it.
View
@@ -2,4 +2,25 @@
function short_link_route() {
+
+ $code = params(0);
+
+ if (!$code) {
+ redirect_to( 'http://www.infop7.org' );
+ }
+
+ $shortlink = ShortLinkQuery::create()
+ ->findOneByShortUrl($code);
+
+ if (!$shortlink) {
+ redirect_to( 'http://www.infop7.org/404' );
+ }
+ else {
+
+ redirect_to(
+ 'http://www.infop7.org/' . $shortlink->getUrl(),
+ array( 'status' => HTTP_MOVED_PERMANENTLY )
+ );
+
+ }
}
View
@@ -54,7 +54,7 @@ function before_sending_header($header) {
if ( strpos($_SERVER['HTTP_HOST'], 's.') === 0 ) {
- dispatch('/:code', 'short_link_route');
+ dispatch('/**', 'short_link_route');
} else {

0 comments on commit c7ad685

Please sign in to comment.