I have one WordPress Blog, which is hosted on Wp-Engine. The URL to the site is www.example.com/blogs
. Now When I access the admin side, it removes the blog
part, and the admin screen is loaded with www.example.com/wp-admin
. Now if I click on any admin link, it will be redirected to 404 page on the www.example.com
. If I disable javascript, it is working fine and the blogs
part is not removed. I am not adding any custom javascript to admin side, but I can see this JS there :
if ( window.history.replaceState ) {
window.history.replaceState( null, null, document.getElementById( 'wp-admin-canonical' ).href + window.location.hash );
}
just below
<link id="wp-admin-canonical" rel="canonical" href="https://www.example.com/wp-admin/theme-editor.php?file=assets%2Fjs%2Fadmin.js&theme=cx">
I think this is causing the issue. Now If I add the following code :
if(strpos( $_SERVER['REQUEST_URI'], "wp-admin") >= 0) {
$_SERVER['HTTP_HOST'] = 'www.example.com/blogs';
}
This fixes the admin side issues, but somehow it is breaking the front-end site and giving 404 for some individual posts.
In my staging environment, wp-admin-canonical
is different, and it is the WPEngine URL hence the Javascript doesn't have an impact, and it is showing an error on the console. But the production, it is the original URL, and so it is replacing the URL.
It would be helpful if someone can let me know how this issue can be fixed. I have the site URL and home URL in the wp-options
settings set to https://www.example.com/blogs