Site icon Hip-Hop Website Design and Development

htaccess redirect not working for wp-admin/edit in site using proxy

Thank you in advance – here is an example of my issue:
I have a subdomain media.example.com. since the main domain example. com is on a different server, A proxy was set it up from the example.com domain. So that the files both wordpress backend and front end will be seen as example.com/media
On the wordpress side:
in wp-config I set up

/** Site URL */
define( ‘WP_HOME’, ‘https://www.example.com/media’ );
define( ‘WP_SITEURL’, ‘https://www.example.com/media’ );

$_SERVER[‘REQUEST_URI’] = str_replace(“/wp-admin/”, “/media/wp-admin/”, $_SERVER[‘REQUEST_URI’]);

Almost all links work well.
The only link that doesn’t work properly is the link to next page in wp-admin on the pages and posts. That link is on the right on the bottom (or top) of those pages and it Does not work.

Those link address that the button shows start at: https://media.example.com/media/wp-admin/edit.php?… INSTEAD OF https://www.example.com/media. So this link is clearly not reading the code in the wp-config. It is not affected by site url setting changes which we set up. To try to fix this issue So I set up a staging site to test it out

I added to the .htaccess on the staging site

RewriteEngine On
RewriteRule ^staging/wp-admin/edit.php$ https://example.com/staging/wp-admin/edit.php [QSA,L,R=301]

when these two lines are in htaccess on staging the link works and I can get to next page. but this code breaks saving pages as draft and as published. So I cannot save pages!

– I get a json error – "Updating failed: the response is not a valid JSON response."
When I take it out the pages can save but the error of getting to the next page returns

So I took out the code.
What do you recommend?
thank you