Changeset 6085 for trunk/wp-includes/canonical.php
- Timestamp:
- 09/11/2007 09:21:40 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/canonical.php
r6026 r6085 2 2 // Based on "Permalink Redirect" from Scott Yang and "Enforce www. Preference" by Mark Jaquith 3 3 4 function redirect_canonical( ) {4 function redirect_canonical($requested_url=NULL, $do_redirect=true) { 5 5 global $wp_rewrite, $posts, $is_IIS; 6 6 … … 8 8 return; 9 9 10 // build the URL in the address bar 11 $requested_url = ( isset($_SERVER['HTTPS'] ) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://'; 12 $requested_url .= $_SERVER['HTTP_HOST']; 13 $requested_url .= $_SERVER['REQUEST_URI']; 10 if ( !$requested_url ) { 11 // build the URL in the address bar 12 $requested_url = ( isset($_SERVER['HTTPS'] ) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://'; 13 $requested_url .= $_SERVER['HTTP_HOST']; 14 $requested_url .= $_SERVER['REQUEST_URI']; 15 } 14 16 15 17 $original = @parse_url($requested_url); … … 127 129 } 128 130 131 // Always trailing slash the 'home' URL 132 if ( $redirect['path'] == $user_home['path'] ) 133 $redirect['path'] = trailingslashit($redirect['path']); 134 129 135 if ( array($original['host'], $original['path'], $original['query']) !== array($redirect['host'], $redirect['path'], $redirect['query']) ) { 130 136 $redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path']; … … 136 142 // var_dump($redirect_url); die(); 137 143 $redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url); 138 wp_redirect($redirect_url, 301); 139 exit(); 144 if ( $do_redirect) { 145 // protect against chained redirects 146 if ( !redirect_canonical($redirect_url, false) ) { 147 wp_redirect($redirect_url, 301); 148 exit(); 149 } else { 150 return false; 151 } 152 } else { 153 return $redirect_url; 154 } 155 } else { 156 return false; 140 157 } 141 158 }
Note: See TracChangeset
for help on using the changeset viewer.