admin管理员组文章数量:1278690
I have a subdomain:
/
I forcibly redirects to directory:
By changing site URL and some RewriteRule on .htaccess.
My .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
RewriteCond %{HTTP:X-Forwarded-Host}i ^example\
RewriteCond %{HTTP_HOST} ^blog\.example\$
RewriteRule ^/?(.*)$ /$1 [L,R=301,NC]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^/?(.*)$ /$1 [L,R=301,NC]
</IfModule>
My wordpress address and site address are:
WordPress Address (URL): /blog
Site Address (URL):
Now the website working fine, but I found an error in wp-admin canonical url on all admin pages:
Uncaught SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'blog.example/wp-admin/index.php'; cannot be created in a document with origin 'example'; and URL 'example/blog/wp-admin/index.php';
When I dig more I found the canonical link is still subdomain( blog.example ) :
<link id="wp-admin-canonical" rel="canonical" href="" />
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, document.getElementById( 'wp-admin-canonical' ).href + window.location.hash );
}
</script>
Is there any solution for changing this canonical url from to
I have a subdomain:
https://blog.example/
I forcibly redirects to directory:
https://www.example/blog
By changing site URL and some RewriteRule on .htaccess.
My .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
RewriteCond %{HTTP:X-Forwarded-Host}i ^example\
RewriteCond %{HTTP_HOST} ^blog\.example\$
RewriteRule ^/?(.*)$ https://www.example/blog/$1 [L,R=301,NC]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^/?(.*)$ https://www.example/blog/$1 [L,R=301,NC]
</IfModule>
My wordpress address and site address are:
WordPress Address (URL): /blog
Site Address (URL): https://www.example/blog
Now the website working fine, but I found an error in wp-admin canonical url on all admin pages:
Uncaught SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'blog.example/wp-admin/index.php'; cannot be created in a document with origin 'example'; and URL 'example/blog/wp-admin/index.php';
When I dig more I found the canonical link is still subdomain( blog.example ) :
<link id="wp-admin-canonical" rel="canonical" href="http://blog.example/wp-admin" />
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, document.getElementById( 'wp-admin-canonical' ).href + window.location.hash );
}
</script>
Is there any solution for changing this canonical url from https://blog.example to https://www.example/blog
Share Improve this question edited Feb 3, 2017 at 20:15 higuita 1053 bronze badges asked Sep 27, 2016 at 10:53 Muhammad RiyazMuhammad Riyaz 1482 silver badges13 bronze badges 3 |2 Answers
Reset to default 2wp-admin-canonical is broken, as it assumes how WordPress is installed.
there was a plugin to fix it, but the plugin was removed from the plugin repository apparently. It is still on github and pluginmirror though: https://github/wp-plugins/remove-wp-canonical-url-admin-hack http://www.pluginmirror/plugins/remove-wp-canonical-url-admin-hack/
Update
The code below didn't really worked for me, as it adds a correct canonical tag but I wasn't able to remove the wrong one with remove_action
.
Also, I found that pagination and sorting links in post and page lists had the wrong URL on it as well.
So the solution has been much simpler, just add $_SERVER['HTTP_HOST'] = 'www.yoursite';
anywhere in wp-config.php
.
Previous answer
I've overrided the wp-admin-canonical
by adding this hooks in functions.php
:
remove_action( 'admin_head', 'wp_admin_canonical_url' );
add_action( 'admin_head', 'wp_set_admin_canonical_url' );
function wp_set_admin_canonical_url() {
$removable_query_args = wp_removable_query_args();
if ( empty( $removable_query_args ) ) {
return;
}
// Ensure we're using an absolute URL.
$current_url = admin_url( preg_replace( '#^[^?]*/wp-admin/#i', '', $_SERVER['REQUEST_URI'] ) );
$filtered_url = remove_query_arg( $removable_query_args, $current_url );
?>
<link id="wp-admin-canonical" rel="canonical" href="<?php echo esc_url( $filtered_url ); ?>" />
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, document.getElementById( 'wp-admin-canonical' ).href + window.location.hash );
}
</script>
<?php
}
I've taken the code from this pull request: https://github/WordPress/wordpress-develop/pull/1504
本文标签: redirectWrong canonical link on wpadmin pages
版权声明:本文标题:redirect - Wrong canonical link on wp-admin pages 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741303090a2371210.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
https
its showinghttp://
– Jess McKenzie Commented Oct 11, 2016 at 19:34