]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - yourls-go.php
Merge pull request #2452 from adigitalife/patch-1
[Github/YOURLS.git] / yourls-go.php
1 <?php
2 define( 'YOURLS_GO', true );
3 require_once( dirname( __FILE__ ) . '/includes/load-yourls.php' );
4
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 );
9
10 // First possible exit:
11 if ( !isset( $keyword ) ) {
12         yourls_do_action( 'redirect_no_keyword' );
13         yourls_redirect( YOURLS_SITE, 301 );
14 }
15
16 // Get URL From Database
17 $url = yourls_get_keyword_longurl( $keyword );
18
19 // URL found
20 if( !empty( $url ) ) {
21     yourls_redirect_shorturl($url, $keyword);
22
23 // URL not found. Either reserved, or page, or doesn't exist
24 } else {
25
26         // Do we have a page?
27         if ( file_exists( YOURLS_PAGEDIR . "/$keyword.php" ) ) {
28                 yourls_page( $keyword );
29
30         // Either reserved id, or no such id
31         } else {
32                 yourls_do_action( 'redirect_keyword_not_found', $keyword );
33
34                 yourls_redirect( YOURLS_SITE, 302 ); // no 404 to tell browser this might change, and also to not pollute logs
35         }
36 }
37 exit();