/var/www/wordpress/wp-admin/includes/admin.php
/var/www/wordpress/wp-admin/includes/bookmark.php
/var/www/wordpress/wp-admin/includes/class-ftp-pure.php
/var/www/wordpress/wp-admin/includes/class-ftp-sockets.php
/var/www/wordpress/wp-admin/includes/class-ftp.php
/var/www/wordpress/wp-admin/includes/class-pclzip.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-base.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-direct.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ftpext.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ftpsockets.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ssh2.php
/var/www/wordpress/wp-admin/includes/class-wp-importer.php
/var/www/wordpress/wp-admin/includes/class-wp-upgrader.php
/var/www/wordpress/wp-admin/includes/comment.php
/var/www/wordpress/wp-admin/includes/continents-cities.php
/var/www/wordpress/wp-admin/includes/dashboard.php
/var/www/wordpress/wp-admin/includes/deprecated.php
/var/www/wordpress/wp-admin/includes/export.php
/var/www/wordpress/wp-admin/includes/file.php
/var/www/wordpress/wp-admin/includes/image-edit.php
/var/www/wordpress/wp-admin/includes/image.php
/var/www/wordpress/wp-admin/includes/import.php
/var/www/wordpress/wp-admin/includes/manifest.php
/var/www/wordpress/wp-admin/includes/media.php
/var/www/wordpress/wp-admin/includes/meta-boxes.php
/var/www/wordpress/wp-admin/includes/misc.php
/var/www/wordpress/wp-admin/includes/ms-deprecated.php
/var/www/wordpress/wp-admin/includes/ms.php
/var/www/wordpress/wp-admin/includes/nav-menu.php
/var/www/wordpress/wp-admin/includes/plugin-install.php
/var/www/wordpress/wp-admin/includes/plugin.php
/var/www/wordpress/wp-admin/includes/post.php
/var/www/wordpress/wp-admin/includes/schema.php
/var/www/wordpress/wp-admin/includes/taxonomy.php
/var/www/wordpress/wp-admin/includes/template.php
/var/www/wordpress/wp-admin/includes/theme-install.php
/var/www/wordpress/wp-admin/includes/theme.php
/var/www/wordpress/wp-admin/includes/update-core.php
/var/www/wordpress/wp-admin/includes/update.php
/var/www/wordpress/wp-admin/includes/upgrade.php
/var/www/wordpress/wp-admin/includes/user.php
/var/www/wordpress/wp-admin/includes/widgets.php
/var/www/wordpress/wp-admin/js/revisions-js.php
/var/www/wordpress/wp-admin/maint/repair.php
/var/www/wordpress/wp-admin/admin-ajax.php
/var/www/wordpress/wp-admin/admin-footer.php
/var/www/wordpress/wp-admin/admin-functions.php
/var/www/wordpress/wp-admin/admin-header.php
/var/www/wordpress/wp-admin/admin-post.php
/var/www/wordpress/wp-admin/admin.php
/var/www/wordpress/wp-admin/async-upload.php
/var/www/wordpress/wp-admin/comment.php
/var/www/wordpress/wp-admin/custom-background.php
/var/www/wordpress/wp-admin/custom-header.php
/var/www/wordpress/wp-admin/edit-attachment-rows.php
/var/www/wordpress/wp-admin/edit-comments.php
/var/www/wordpress/wp-admin/edit-form-advanced.php
/var/www/wordpress/wp-admin/edit-form-comment.php
/var/www/wordpress/wp-admin/edit-link-categories.php
/var/www/wordpress/wp-admin/edit-link-category-form.php
/var/www/wordpress/wp-admin/edit-link-form.php
/var/www/wordpress/wp-admin/edit-post-rows.php
/var/www/wordpress/wp-admin/edit-tag-form.php
/var/www/wordpress/wp-admin/edit-tags.php
/var/www/wordpress/wp-admin/edit.php
/var/www/wordpress/wp-admin/export.php
/var/www/wordpress/wp-admin/gears-manifest.php
/var/www/wordpress/wp-admin/import.php
/var/www/wordpress/wp-admin/index-extra.php
/var/www/wordpress/wp-admin/index.php
/var/www/wordpress/wp-admin/install-helper.php
/var/www/wordpress/wp-admin/install.php
/var/www/wordpress/wp-admin/link-add.php
/var/www/wordpress/wp-admin/link-category.php
/var/www/wordpress/wp-admin/link-manager.php
/var/www/wordpress/wp-admin/link-parse-opml.php
/var/www/wordpress/wp-admin/link.php
/var/www/wordpress/wp-admin/load-scripts.php
/var/www/wordpress/wp-admin/load-styles.php
/var/www/wordpress/wp-admin/media-new.php
/var/www/wordpress/wp-admin/media-upload.php
/var/www/wordpress/wp-admin/media.php
/var/www/wordpress/wp-admin/menu-header.php
/var/www/wordpress/wp-admin/menu.php
/var/www/wordpress/wp-admin/moderation.php
/var/www/wordpress/wp-admin/ms-admin.php
/var/www/wordpress/wp-admin/ms-delete-site.php
/var/www/wordpress/wp-admin/ms-edit.php
/var/www/wordpress/wp-admin/ms-options.php
/var/www/wordpress/wp-admin/ms-sites.php
/var/www/wordpress/wp-admin/ms-themes.php
/var/www/wordpress/wp-admin/ms-upgrade-network.php
/var/www/wordpress/wp-admin/ms-users.php
/var/www/wordpress/wp-admin/my-sites.php
/var/www/wordpress/wp-admin/nav-menus.php
/var/www/wordpress/wp-admin/network.php
/var/www/wordpress/wp-admin/options-discussion.php
/var/www/wordpress/wp-admin/options-general.php
/var/www/wordpress/wp-admin/options-head.php
/var/www/wordpress/wp-admin/options-media.php
/var/www/wordpress/wp-admin/options-permalink.php
/var/www/wordpress/wp-admin/options-privacy.php
/var/www/wordpress/wp-admin/options-reading.php
/var/www/wordpress/wp-admin/options-writing.php
/var/www/wordpress/wp-admin/options.php
/var/www/wordpress/wp-admin/plugin-editor.php
/var/www/wordpress/wp-admin/plugin-install.php
/var/www/wordpress/wp-admin/plugins.php
/var/www/wordpress/wp-admin/post-new.php
/var/www/wordpress/wp-admin/post.php
/var/www/wordpress/wp-admin/press-this.php
/var/www/wordpress/wp-admin/profile.php
/var/www/wordpress/wp-admin/revision.php
/var/www/wordpress/wp-admin/setup-config.php
/var/www/wordpress/wp-admin/sidebar.php
/var/www/wordpress/wp-admin/theme-editor.php
/var/www/wordpress/wp-admin/theme-install.php
/var/www/wordpress/wp-admin/themes.php
/var/www/wordpress/wp-admin/tools.php
/var/www/wordpress/wp-admin/update-core.php
/var/www/wordpress/wp-admin/update.php
/var/www/wordpress/wp-admin/upgrade-functions.php
/var/www/wordpress/wp-admin/upgrade.php
/var/www/wordpress/wp-admin/upload.php
/var/www/wordpress/wp-admin/user-edit.php
/var/www/wordpress/wp-admin/user-new.php
/var/www/wordpress/wp-admin/users.php
/var/www/wordpress/wp-admin/widgets.php
/var/www/wordpress/wp-content/languages/ru_RU.php
/var/www/wordpress/wp-content/plugins/akismet/akismet.php
/var/www/wordpress/wp-content/plugins/rh/rh.php
/var/www/wordpress/wp-content/plugins/hello.php
/var/www/wordpress/wp-content/plugins/index.php
/var/www/wordpress/wp-content/themes/twentyten/404.php
/var/www/wordpress/wp-content/themes/twentyten/archive.php
/var/www/wordpress/wp-content/themes/twentyten/attachment.php
/var/www/wordpress/wp-content/themes/twentyten/author.php
/var/www/wordpress/wp-content/themes/twentyten/category.php
/var/www/wordpress/wp-content/themes/twentyten/comments.php
/var/www/wordpress/wp-content/themes/twentyten/footer.php
/var/www/wordpress/wp-content/themes/twentyten/functions.php
/var/www/wordpress/wp-content/themes/twentyten/header.php
/var/www/wordpress/wp-content/themes/twentyten/index.php
/var/www/wordpress/wp-content/themes/twentyten/loop.php
/var/www/wordpress/wp-content/themes/twentyten/onecolumn-page.php
/var/www/wordpress/wp-content/themes/twentyten/page.php
/var/www/wordpress/wp-content/themes/twentyten/search.php
/var/www/wordpress/wp-content/themes/twentyten/sidebar-footer.php
/var/www/wordpress/wp-content/themes/twentyten/sidebar.php
/var/www/wordpress/wp-content/themes/twentyten/single.php
/var/www/wordpress/wp-content/themes/twentyten/tag.php
/var/www/wordpress/wp-content/themes/index.php
/var/www/wordpress/wp-content/index.php
/var/www/wordpress/wp-includes/js/tinymce/langs/wp-langs.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/Logger.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/EnchantSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/GoogleSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/PSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/PSpellShell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/SpellChecker.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/includes/general.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/config.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/rpc.php
/var/www/wordpress/wp-includes/js/tinymce/wp-mce-help.php
/var/www/wordpress/wp-includes/js/tinymce/wp-tinymce.php
/var/www/wordpress/wp-includes/pomo/entry.php
/var/www/wordpress/wp-includes/pomo/mo.php
/var/www/wordpress/wp-includes/pomo/po.php
/var/www/wordpress/wp-includes/pomo/streams.php
/var/www/wordpress/wp-includes/pomo/translations.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/native.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/shell.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/string.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/xdiff.php
/var/www/wordpress/wp-includes/Text/Diff/Renderer/inline.php
/var/www/wordpress/wp-includes/Text/Diff/Renderer.php
/var/www/wordpress/wp-includes/Text/Diff.php
/var/www/wordpress/wp-includes/theme-compat/comments-popup.php
/var/www/wordpress/wp-includes/theme-compat/comments.php
/var/www/wordpress/wp-includes/theme-compat/footer.php
/var/www/wordpress/wp-includes/theme-compat/header.php
/var/www/wordpress/wp-includes/theme-compat/sidebar.php
/var/www/wordpress/wp-includes/atomlib.php
/var/www/wordpress/wp-includes/author-template.php
/var/www/wordpress/wp-includes/bookmark-template.php
/var/www/wordpress/wp-includes/bookmark.php
/var/www/wordpress/wp-includes/cache.php
/var/www/wordpress/wp-includes/canonical.php
#CodeDescriptions
1<?php
2/**
3 * Canonical API to handle WordPress Redirecting
4 *
5 * Based on "Permalink Redirect" from Scott Yang and "Enforce www. Preference"
6 * by Mark Jaquith
7 *
8 * @package WordPress
9 * @since 2.3.0
10 */
11
12/**
13 * Redirects incoming links to the proper URL based on the site url.
14 *
15 * Search engines consider www.somedomain.com and somedomain.com to be two
16 * different URLs when they both go to the same location. This SEO enhancement
17 * prevents penality for duplicate content by redirecting all incoming links to
18 * one or the other.
19 *
20 * Prevents redirection for feeds, trackbacks, searches, comment popup, and
21 * admin URLs. Does not redirect on IIS, page/post previews, and on form data.
22 *
23 * Will also attempt to find the correct link when a user enters a URL that does
24 * not exist based on exact WordPress query. Will instead try to parse the URL
25 * or query in an attempt to figure the correct page to go to.
26 *
27 * @since 2.3.0
28 * @uses $wp_rewrite
29 * @uses $is_IIS
30 *
31 * @param string $requested_url Optional. The URL that was requested, used to
32 * figure if redirect is needed.
33 * @param bool $do_redirect Optional. Redirect to the new URL.
34 * @return null|false|string Null, if redirect not needed. False, if redirect
35 * not needed or the string of the URL
36 */
37function redirect_canonical($requested_url=null, $do_redirect=true) {
38 global $wp_rewrite, $is_IIS, $wp_query, $wpdb;
39
40 if ( is_trackback() || is_search() || is_comments_popup() || is_admin() || $is_IIS || ( isset($_POST) && count($_POST) ) || is_preview() || is_robots() )
41 return;
42
43 if ( !$requested_url ) {
44 // build the URL in the address bar
45 $requested_url = is_ssl() ? 'https://' : 'http://';
46 $requested_url .= $_SERVER['HTTP_HOST'];
47 $requested_url .= $_SERVER['REQUEST_URI'];
48 }
49
50 $original = @parse_url($requested_url);
51 if ( false === $original )
52 return;
53
54 // Some PHP setups turn requests for / into /index.php in REQUEST_URI
55 // See: http://trac.wordpress.org/ticket/5017
56 // See: http://trac.wordpress.org/ticket/7173
57 // Disabled, for now:
58 // $original['path'] = preg_replace('|/index\.php$|', '/', $original['path']);
59
60 $redirect = $original;
61 $redirect_url = false;
62
63 // Notice fixing
64 if ( !isset($redirect['path']) )
65 $redirect['path'] = '';
66 if ( !isset($redirect['query']) )
67 $redirect['query'] = '';
68
69 if ( is_singular() && 1 > $wp_query->post_count && ($id = get_query_var('p')) ) {
70
71 $vars = $wpdb->get_results( $wpdb->prepare("SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $id) );
72
73 if ( isset($vars[0]) && $vars = $vars[0] ) {
74 if ( 'revision' == $vars->post_type && $vars->post_parent > 0 )
75 $id = $vars->post_parent;
76
77 if ( $redirect_url = get_permalink($id) )
78 $redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id', 'post_type'), $redirect['query']);
79 }
80 }
81
82 // These tests give us a WP-generated permalink
83 if ( is_404() ) {
84
85 // Redirect ?page_id, ?p=, ?attachment_id= to their respective url's
86 $id = max( get_query_var('p'), get_query_var('page_id'), get_query_var('attachment_id') );
87 if ( $id && $redirect_post = get_post($id) ) {
88 $post_type_obj = get_post_type_object($redirect_post->post_type);
89 if ( $post_type_obj->public ) {
90 $redirect_url = get_permalink($redirect_post);
91 $redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id', 'post_type'), $redirect['query']);
92 }
93 }
94
95 if ( ! $redirect_url )
96 $redirect_url = redirect_guess_404_permalink();
97
98 } elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) {
99 // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101
100 if ( is_attachment() && !empty($_GET['attachment_id']) && ! $redirect_url ) {
101 if ( $redirect_url = get_attachment_link(get_query_var('attachment_id')) )
102 $redirect['query'] = remove_query_arg('attachment_id', $redirect['query']);
103 } elseif ( is_single() && !empty($_GET['p']) && ! $redirect_url ) {
104 if ( $redirect_url = get_permalink(get_query_var('p')) )
105 $redirect['query'] = remove_query_arg(array('p', 'post_type'), $redirect['query']);
106 if ( get_query_var( 'page' ) ) {
107 $redirect_url = trailingslashit( $redirect_url ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' );
108 $redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
109 }
110 } elseif ( is_single() && !empty($_GET['name']) && ! $redirect_url ) {
111 if ( $redirect_url = get_permalink( $wp_query->get_queried_object_id() ) )
112 $redirect['query'] = remove_query_arg('name', $redirect['query']);
113 } elseif ( is_page() && !empty($_GET['page_id']) && ! $redirect_url ) {
114 if ( $redirect_url = get_permalink(get_query_var('page_id')) )
115 $redirect['query'] = remove_query_arg('page_id', $redirect['query']);
116 } elseif ( is_page() && !is_feed() && isset($wp_query->queried_object) && 'page' == get_option('show_on_front') && $wp_query->queried_object->ID == get_option('page_on_front') && ! $redirect_url ) {
117 $redirect_url = home_url('/');
118 } elseif ( is_home() && !empty($_GET['page_id']) && 'page' == get_option('show_on_front') && get_query_var('page_id') == get_option('page_for_posts') && ! $redirect_url ) {
119 if ( $redirect_url = get_permalink(get_option('page_for_posts')) )
120 $redirect['query'] = remove_query_arg('page_id', $redirect['query']);
121 } elseif ( !empty($_GET['m']) && ( is_year() || is_month() || is_day() ) ) {
122 $m = get_query_var('m');
123 switch ( strlen($m) ) {
124 case 4: // Yearly
125 $redirect_url = get_year_link($m);
126 break;
127 case 6: // Monthly
128 $redirect_url = get_month_link( substr($m, 0, 4), substr($m, 4, 2) );
129 break;
130 case 8: // Daily
131 $redirect_url = get_day_link(substr($m, 0, 4), substr($m, 4, 2), substr($m, 6, 2));
132 break;
133 }
134 if ( $redirect_url )
135 $redirect['query'] = remove_query_arg('m', $redirect['query']);
136 // now moving on to non ?m=X year/month/day links
137 } elseif ( is_day() && get_query_var('year') && get_query_var('monthnum') && !empty($_GET['day']) ) {
138 if ( $redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day')) )
139 $redirect['query'] = remove_query_arg(array('year', 'monthnum', 'day'), $redirect['query']);
140 } elseif ( is_month() && get_query_var('year') && !empty($_GET['monthnum']) ) {
141 if ( $redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum')) )
142 $redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']);
143 } elseif ( is_year() && !empty($_GET['year']) ) {
144 if ( $redirect_url = get_year_link(get_query_var('year')) )
145 $redirect['query'] = remove_query_arg('year', $redirect['query']);
146 } elseif ( is_author() && !empty($_GET['author']) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) {
147 $author = get_userdata(get_query_var('author'));
148 if ( false !== $author && $redirect_url = get_author_posts_url($author->ID, $author->user_nicename) )
149 $redirect['query'] = remove_query_arg('author', $redirect['query']);
150 } elseif ( is_category() || is_tag() || is_tax() ) { // Terms (Tags/categories)
151
152 $term_count = 0;
153 foreach ( array('category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in',
154 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and') as $key )
155 $term_count += count($wp_query->query_vars[$key]);
156
157 $obj = $wp_query->get_queried_object();
158
159 if ( $term_count <= 1 && !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) )
160 && !is_wp_error($tax_url) && $redirect['query'] ) {
161 if ( is_category() ) {
162 $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']);
163 } elseif ( is_tag() ) {
164 $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']);
165 } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too:
166 $tax = get_taxonomy( $obj->taxonomy );
167 if ( false !== $tax->query_var)
168 $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']);
169 else
170 $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']);
171 }
172
173 $tax_url = parse_url($tax_url);
174 if ( ! empty($tax_url['query']) ) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=..
175 parse_str($tax_url['query'], $query_vars);
176 $redirect['query'] = add_query_arg($query_vars, $redirect['query']);
177 } else { // Taxonomy is accessable via a "pretty-URL"
178 $redirect['path'] = $tax_url['path'];
179 }
180
181 }
182 } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false ) {
183 $category = get_term_by('slug', get_query_var('category_name'), 'category');
184 $post_terms = wp_get_object_terms($wp_query->get_queried_object_id(), 'category', array('fields' => 'tt_ids'));
185 if ( (!$category || is_wp_error($category)) || ( !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms) ) )
186 $redirect_url = get_permalink($wp_query->get_queried_object_id());
187 }
188
189 // paging and feeds
190 if ( get_query_var('paged') || is_feed() || get_query_var('cpage') ) {
191 if ( !$redirect_url )
192 $redirect_url = $requested_url;
193 $paged_redirect = @parse_url($redirect_url);
194 while ( preg_match( '#/page/?[0-9]+?(/+)?$#', $paged_redirect['path'] ) || preg_match( '#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $paged_redirect['path'] ) || preg_match( '#/comment-page-[0-9]+(/+)?$#', $paged_redirect['path'] ) ) {
195 // Strip off paging and feed
196 $paged_redirect['path'] = preg_replace('#/page/?[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing paging
197 $paged_redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $paged_redirect['path']); // strip off feed endings
198 $paged_redirect['path'] = preg_replace('#/comment-page-[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing comment paging
199 }
200
201 $addl_path = '';
202 if ( is_feed() ) {
203 $addl_path = !empty( $addl_path ) ? trailingslashit($addl_path) : '';
204 if ( get_query_var( 'withcomments' ) )
205 $addl_path .= 'comments/';
206 $addl_path .= user_trailingslashit( 'feed/' . ( ( get_default_feed() == get_query_var('feed') || 'feed' == get_query_var('feed') ) ? '' : get_query_var('feed') ), 'feed' );
207 $redirect['query'] = remove_query_arg( 'feed', $redirect['query'] );
208 }
209
210 if ( get_query_var('paged') > 0 ) {
211 $paged = get_query_var('paged');
212 $redirect['query'] = remove_query_arg( 'paged', $redirect['query'] );
213 if ( !is_feed() ) {
214 if ( $paged > 1 && !is_single() ) {
215 $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit("page/$paged", 'paged');
216 } elseif ( !is_single() ) {
217 $addl_path = !empty( $addl_path ) ? trailingslashit($addl_path) : '';
218 }
219 } elseif ( $paged > 1 ) {
220 $redirect['query'] = add_query_arg( 'paged', $paged, $redirect['query'] );
221 }
222 }
223
224 if ( get_option('page_comments') && ( ( 'newest' == get_option('default_comments_page') && get_query_var('cpage') > 0 ) || ( 'newest' != get_option('default_comments_page') && get_query_var('cpage') > 1 ) ) ) {
225 $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit( 'comment-page-' . get_query_var('cpage'), 'commentpaged' );
226 $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] );
227 }
228
229 $paged_redirect['path'] = user_trailingslashit( preg_replace('|/index.php/?$|', '/', $paged_redirect['path']) ); // strip off trailing /index.php/
230 if ( !empty( $addl_path ) && $wp_rewrite->using_index_permalinks() && strpos($paged_redirect['path'], '/index.php/') === false )
231 $paged_redirect['path'] = trailingslashit($paged_redirect['path']) . 'index.php/';
232 if ( !empty( $addl_path ) )
233 $paged_redirect['path'] = trailingslashit($paged_redirect['path']) . $addl_path;
234 $redirect_url = $paged_redirect['scheme'] . '://' . $paged_redirect['host'] . $paged_redirect['path'];
235 $redirect['path'] = $paged_redirect['path'];
236 }
237 }
238
239 // tack on any additional query vars
240 $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] );
241 if ( $redirect_url && !empty($redirect['query']) ) {
242 if ( strpos($redirect_url, '?') !== false )
243 $redirect_url .= '&';
244 else
245 $redirect_url .= '?';
246 $redirect_url .= $redirect['query'];
247 }
248
249 if ( $redirect_url )
250 $redirect = @parse_url($redirect_url);
251
252 // www.example.com vs example.com
253 $user_home = @parse_url(home_url());
254 if ( !empty($user_home['host']) )
255 $redirect['host'] = $user_home['host'];
256 if ( empty($user_home['path']) )
257 $user_home['path'] = '/';
258
259 // Handle ports
260 if ( !empty($user_home['port']) )
261 $redirect['port'] = $user_home['port'];
262 else
263 unset($redirect['port']);
264
265 // trailing /index.php
266 $redirect['path'] = preg_replace('|/index.php/*?$|', '/', $redirect['path']);
267
268 // Remove trailing spaces from the path
269 $redirect['path'] = preg_replace( '#(%20| )+$#', '', $redirect['path'] );
270
271 if ( !empty( $redirect['query'] ) ) {
272 // Remove trailing spaces from certain terminating query string args
273 $redirect['query'] = preg_replace( '#((p|page_id|cat|tag)=[^&]*?)(%20| )+$#', '$1', $redirect['query'] );
274
275 // Clean up empty query strings
276 $redirect['query'] = trim(preg_replace( '#(^|&)(p|page_id|cat|tag)=?(&|$)#', '&', $redirect['query']), '&');
277
278 // Remove redundant leading ampersands
279 $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] );
280 }
281
282 // strip /index.php/ when we're not using PATHINFO permalinks
283 if ( !$wp_rewrite->using_index_permalinks() )
284 $redirect['path'] = str_replace('/index.php/', '/', $redirect['path']);
285
286 // trailing slashes
287 if ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && !is_404() && (!is_front_page() || ( is_front_page() && (get_query_var('paged') > 1) ) ) ) {
288 $user_ts_type = '';
289 if ( get_query_var('paged') > 0 ) {
290 $user_ts_type = 'paged';
291 } else {
292 foreach ( array('single', 'category', 'page', 'day', 'month', 'year', 'home') as $type ) {
293 $func = 'is_' . $type;
294 if ( call_user_func($func) ) {
295 $user_ts_type = $type;
296 break;
297 }
298 }
299 }
300 $redirect['path'] = user_trailingslashit($redirect['path'], $user_ts_type);
301 } elseif ( is_front_page() ) {
302 $redirect['path'] = trailingslashit($redirect['path']);
303 }
304
305 // Strip multiple slashes out of the URL
306 if ( strpos($redirect['path'], '//') > -1 )
307 $redirect['path'] = preg_replace('|/+|', '/', $redirect['path']);
308
309 // Always trailing slash the Front Page URL
310 if ( trailingslashit( $redirect['path'] ) == trailingslashit( $user_home['path'] ) )
311 $redirect['path'] = trailingslashit($redirect['path']);
312
313 // Ignore differences in host capitalization, as this can lead to infinite redirects
314 // Only redirect no-www <=> yes-www
315 if ( strtolower($original['host']) == strtolower($redirect['host']) ||
316 ( strtolower($original['host']) != 'www.' . strtolower($redirect['host']) && 'www.' . strtolower($original['host']) != strtolower($redirect['host']) ) )
317 $redirect['host'] = $original['host'];
318
319 $compare_original = array($original['host'], $original['path']);
320
321 if ( !empty( $original['port'] ) )
322 $compare_original[] = $original['port'];
323
324 if ( !empty( $original['query'] ) )
325 $compare_original[] = $original['query'];
326
327 $compare_redirect = array($redirect['host'], $redirect['path']);
328
329 if ( !empty( $redirect['port'] ) )
330 $compare_redirect[] = $redirect['port'];
331
332 if ( !empty( $redirect['query'] ) )
333 $compare_redirect[] = $redirect['query'];
334
335 if ( $compare_original !== $compare_redirect ) {
336 $redirect_url = $redirect['scheme'] . '://' . $redirect['host'];
337 if ( !empty($redirect['port']) )
338 $redirect_url .= ':' . $redirect['port'];
339 $redirect_url .= $redirect['path'];
340 if ( !empty($redirect['query']) )
341 $redirect_url .= '?' . $redirect['query'];
342 }
343
344 if ( !$redirect_url || $redirect_url == $requested_url )
345 return false;
346
347 // Hex encoded octets are case-insensitive.
348 if ( false !== strpos($requested_url, '%') ) {
349 if ( !function_exists('lowercase_octets') ) {
350 function lowercase_octets($matches) {
351 return strtolower( $matches[0] );
352 }
353 }
354 $requested_url = preg_replace_callback('|%[a-fA-F0-9][a-fA-F0-9]|', 'lowercase_octets', $requested_url);
355 }
356
357 // Note that you can use the "redirect_canonical" filter to cancel a canonical redirect for whatever reason by returning FALSE
358 $redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url);
359
360 if ( !$redirect_url || $redirect_url == $requested_url ) // yes, again -- in case the filter aborted the request
361 return false;
362
363 if ( $do_redirect ) {
364 // protect against chained redirects
365 if ( !redirect_canonical($redirect_url, false) ) {
366 wp_redirect($redirect_url, 301);
367 exit();
368 } else {
369 // Debug
370 // die("1: $redirect_url<br />2: " . redirect_canonical( $redirect_url, false ) );
371 return false;
372 }
373 } else {
374 return $redirect_url;
375 }
376}
377
378/**
379 * Attempts to guess correct post based on query vars.
380 *
381 * @since 2.3.0
382 * @uses $wpdb
383 *
384 * @return bool|string Returns False, if it can't find post, returns correct
385 * location on success.
386 */
387function redirect_guess_404_permalink() {
388 global $wpdb;
389
390 if ( !get_query_var('name') )
391 return false;
392
393 $where = $wpdb->prepare("post_name LIKE %s", get_query_var('name') . '%');
394
395 // if any of post_type, year, monthnum, or day are set, use them to refine the query
396 if ( get_query_var('post_type') )
397 $where .= $wpdb->prepare(" AND post_type = %s", get_query_var('post_type'));
398 if ( get_query_var('year') )
399 $where .= $wpdb->prepare(" AND YEAR(post_date) = %d", get_query_var('year'));
400 if ( get_query_var('monthnum') )
401 $where .= $wpdb->prepare(" AND MONTH(post_date) = %d", get_query_var('monthnum'));
402 if ( get_query_var('day') )
403 $where .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", get_query_var('day'));
404
405 $post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'");
406 if ( !$post_id )
407 return false;
408 return get_permalink($post_id);
409}
410
411add_action('template_redirect', 'redirect_canonical');
412
413?>
414
/var/www/wordpress/wp-includes/capabilities.php
/var/www/wordpress/wp-includes/category-template.php
/var/www/wordpress/wp-includes/category.php
/var/www/wordpress/wp-includes/class-feed.php
/var/www/wordpress/wp-includes/class-http.php
/var/www/wordpress/wp-includes/class-IXR.php
/var/www/wordpress/wp-includes/class-json.php
/var/www/wordpress/wp-includes/class-oembed.php
/var/www/wordpress/wp-includes/class-phpass.php
/var/www/wordpress/wp-includes/class-phpmailer.php
/var/www/wordpress/wp-includes/class-pop3.php
/var/www/wordpress/wp-includes/class-simplepie.php
/var/www/wordpress/wp-includes/class-smtp.php
/var/www/wordpress/wp-includes/class-snoopy.php
/var/www/wordpress/wp-includes/class.wp-dependencies.php
/var/www/wordpress/wp-includes/class.wp-scripts.php
/var/www/wordpress/wp-includes/class.wp-styles.php
/var/www/wordpress/wp-includes/classes.php
/var/www/wordpress/wp-includes/comment-template.php
/var/www/wordpress/wp-includes/comment.php
/var/www/wordpress/wp-includes/compat.php
/var/www/wordpress/wp-includes/cron.php
/var/www/wordpress/wp-includes/default-constants.php
/var/www/wordpress/wp-includes/default-embeds.php
/var/www/wordpress/wp-includes/default-filters.php
/var/www/wordpress/wp-includes/default-widgets.php
/var/www/wordpress/wp-includes/deprecated.php
/var/www/wordpress/wp-includes/feed-atom-comments.php
/var/www/wordpress/wp-includes/feed-atom.php
/var/www/wordpress/wp-includes/feed-rdf.php
/var/www/wordpress/wp-includes/feed-rss.php
/var/www/wordpress/wp-includes/feed-rss2-comments.php
/var/www/wordpress/wp-includes/feed-rss2.php
/var/www/wordpress/wp-includes/feed.php
/var/www/wordpress/wp-includes/formatting.php
/var/www/wordpress/wp-includes/functions.php
/var/www/wordpress/wp-includes/functions.wp-scripts.php
/var/www/wordpress/wp-includes/functions.wp-styles.php
/var/www/wordpress/wp-includes/general-template.php
/var/www/wordpress/wp-includes/http.php
/var/www/wordpress/wp-includes/kses.php
/var/www/wordpress/wp-includes/l10n.php
/var/www/wordpress/wp-includes/link-template.php
/var/www/wordpress/wp-includes/load.php
/var/www/wordpress/wp-includes/locale.php
/var/www/wordpress/wp-includes/media.php
/var/www/wordpress/wp-includes/meta.php
/var/www/wordpress/wp-includes/ms-blogs.php
/var/www/wordpress/wp-includes/ms-default-constants.php
/var/www/wordpress/wp-includes/ms-default-filters.php
/var/www/wordpress/wp-includes/ms-deprecated.php
/var/www/wordpress/wp-includes/ms-files.php
/var/www/wordpress/wp-includes/ms-functions.php
/var/www/wordpress/wp-includes/ms-load.php
/var/www/wordpress/wp-includes/ms-settings.php
/var/www/wordpress/wp-includes/nav-menu-template.php
/var/www/wordpress/wp-includes/nav-menu.php
/var/www/wordpress/wp-includes/pluggable-deprecated.php
/var/www/wordpress/wp-includes/pluggable.php
/var/www/wordpress/wp-includes/plugin.php
/var/www/wordpress/wp-includes/post-template.php
/var/www/wordpress/wp-includes/post-thumbnail-template.php
/var/www/wordpress/wp-includes/post.php
/var/www/wordpress/wp-includes/query.php
/var/www/wordpress/wp-includes/registration-functions.php
/var/www/wordpress/wp-includes/registration.php
/var/www/wordpress/wp-includes/rewrite.php
/var/www/wordpress/wp-includes/rss-functions.php
/var/www/wordpress/wp-includes/rss.php
/var/www/wordpress/wp-includes/script-loader.php
/var/www/wordpress/wp-includes/shortcodes.php
/var/www/wordpress/wp-includes/taxonomy.php
/var/www/wordpress/wp-includes/template-loader.php
/var/www/wordpress/wp-includes/theme.php
/var/www/wordpress/wp-includes/update.php
/var/www/wordpress/wp-includes/user.php
/var/www/wordpress/wp-includes/vars.php
/var/www/wordpress/wp-includes/version.php
/var/www/wordpress/wp-includes/widgets.php
/var/www/wordpress/wp-includes/wp-db.php
/var/www/wordpress/wp-includes/wp-diff.php
/var/www/wordpress/index.php
/var/www/wordpress/wp-activate.php
/var/www/wordpress/wp-app.php
/var/www/wordpress/wp-atom.php
/var/www/wordpress/wp-blog-header.php
/var/www/wordpress/wp-comments-post.php
/var/www/wordpress/wp-commentsrss2.php
/var/www/wordpress/wp-config-sample.php
/var/www/wordpress/wp-cron.php
/var/www/wordpress/wp-feed.php
/var/www/wordpress/wp-links-opml.php
/var/www/wordpress/wp-load.php
/var/www/wordpress/wp-login.php
/var/www/wordpress/wp-mail.php
/var/www/wordpress/wp-pass.php
/var/www/wordpress/wp-rdf.php
/var/www/wordpress/wp-register.php
/var/www/wordpress/wp-rss.php
/var/www/wordpress/wp-rss2.php
/var/www/wordpress/wp-settings.php
/var/www/wordpress/wp-signup.php
/var/www/wordpress/wp-trackback.php
/var/www/wordpress/xmlrpc.php