Skip to content
Permalink
Browse files

Tell (Google)bots not to index short URLs

Should fix #2202
  • Loading branch information...
ozh committed Aug 5, 2018
1 parent e0e3d5e commit 364c03a5f79c0012bf3ac4c90215941dd45e8943
Showing with 30 additions and 10 deletions.
  1. +28 −0 includes/functions.php
  2. +2 −10 yourls-go.php
@@ -719,6 +719,34 @@ function yourls_redirect( $location, $code = 301 ) {
die();
}
/**
* Redirect to an existing short URL
*
* Redirect client to an existing short URL (no check performed) and execute misc tasks: update
* clicks for short URL, update logs, and send a nocache header to prevent bots indexing short
* URLS (see #2202)
*
* @since 1.7.3
* @param string $url
* @param string $keyword
*/
function yourls_redirect_shorturl($url, $keyword) {
yourls_do_action('redirect_shorturl', $url, $keyword);
// Update click count in main table
$update_clicks = yourls_update_clicks($keyword);
// Update detailed log for stats
$log_redirect = yourls_log_redirect($keyword);
// Tell (Google)bots not to index this short URL, see #2202
if( !headers_sent() ) {
header("X-Robots-Tag: noindex", true);
}
yourls_redirect($url, 301);
}
/**
* Set HTTP status header
*
@@ -18,15 +18,7 @@
// URL found
if( !empty( $url ) ) {
yourls_do_action( 'redirect_shorturl', $url, $keyword );
// Update click count in main table
$update_clicks = yourls_update_clicks( $keyword );
// Update detailed log for stats
$log_redirect = yourls_log_redirect( $keyword );
yourls_redirect( $url, 301 );
yourls_redirect_shorturl($url, $keyword);
// URL not found. Either reserved, or page, or doesn't exist
} else {
@@ -38,7 +30,7 @@
// Either reserved id, or no such id
} else {
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
}
}

0 comments on commit 364c03a

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.