1

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&amp;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

Happy Coder
  • 4,255
  • 13
  • 75
  • 152

1 Answers1

0

The code you added to modify $_SERVER['HTTP_HOST'] might be causing conflicts with the WordPress core functionalities.

You may try the following:

Clear Cache

Check .htaccess: Ensure that your .htaccess file is not causing any URL rewriting issues.

WordPress Settings Update: Make sure that the "WordPress Address (URL)" and "Site Address (URL)" settings in the WordPress admin dashboard are set correctly to https://www.example.com/blogs. To do this, go to Settings > General and update the "WordPress Address (URL)" and "Site Address (URL)" fields.

Wakil Ahmed
  • 1,053
  • 1
  • 8
  • 16