forked from YOURLS/YOURLS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yourls-go.php
28 lines (23 loc) · 821 Bytes
/
yourls-go.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
define( 'YOURLS_GO', true );
require_once( dirname( __FILE__ ) . '/includes/load-yourls.php' );
// Variables should be defined in yourls-loader.php
if( !isset( $keyword ) ) {
yourls_do_action( 'redirect_no_keyword' );
yourls_redirect( YOURLS_SITE, 301 );
}
$keyword = yourls_sanitize_keyword($keyword);
// if we have a page, display and exit
if( yourls_is_page($keyword) ) {
yourls_page( $keyword );
return;
}
// if we can get a long URL from the DB, redirect
if( $url = yourls_get_keyword_longurl( $keyword ) ) {
yourls_redirect_shorturl($url, $keyword);
return;
}
// Either reserved keyword, or no such keyword
yourls_do_action( 'redirect_keyword_not_found', $keyword );
yourls_redirect( YOURLS_SITE, 302 ); // no 404 to tell browser this might change, and also to not pollute logs
exit();