2 define( 'YOURLS_GO', true );
3 require_once( dirname( __FILE__ ) . '/includes/load-yourls.php' );
5 // Variables should be defined in yourls-loader.php, if not try GET request (old behavior of yourls-go.php)
6 if( !isset( $keyword ) && isset( $_GET['id'] ) )
7 $keyword = $_GET['id'];
8 $keyword = yourls_sanitize_string( $keyword );
10 // First possible exit:
11 if ( !isset( $keyword ) ) {
12 yourls_do_action( 'redirect_no_keyword' );
13 yourls_redirect( YOURLS_SITE, 301 );
16 // Get URL From Database
17 $url = yourls_get_keyword_longurl( $keyword );
20 if( !empty( $url ) ) {
21 yourls_do_action( 'redirect_shorturl', $url, $keyword );
23 // Update click count in main table
24 $update_clicks = yourls_update_clicks( $keyword );
26 // Update detailed log for stats
27 $log_redirect = yourls_log_redirect( $keyword );
29 yourls_redirect( $url, 301 );
31 // URL not found. Either reserved, or page, or doesn't exist
35 if ( file_exists( YOURLS_PAGEDIR . "/$keyword.php" ) ) {
36 yourls_page( $keyword );
38 // Either reserved id, or no such id
40 yourls_do_action( 'redirect_keyword_not_found', $keyword );
42 yourls_redirect( YOURLS_SITE, 302 ); // no 404 to tell browser this might change, and also to not pollute logs