Redirecting WordPress site to Ember, except dashboard and API

I’ve built an Ember front-end to a WordPress site. The two are hosted on separate domains so when a user clicks “View page” in the WordPress dashboard they are sent to the page on the API site rather than the front-end of the site.

I have created routes to match the WordPress site, so I want to simply redirect everything from the API to the Ember site, with the exception of the dashboard and API endpoints. This will also be useful if, for whatever reason, someone navigates directly to the API in their browser.

Read More

So I want the following:

example-api.com/abc ~> example.com/abc
example-api.com/abc/def ~> example.com/abc/def

example-api.com/wp-admin ~> work as normal
example-api.com/wp-json ~> work as normal

I’ve tried the following so far:

RewriteEngine On
RewriteBase /
RewriteRule ^!(wp-json|wp-admin)($|/) http://example.com/$1 [R=301,L]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

but that seems to redirect everything.

Next:

RewriteEngine On
RewriteBase /
RewriteRule ^(wp-json|wp-admin)($|/) /index.php [L]
RewriteRule ^index.php$ - [L]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

as I thought that it would just forward the request to wp-json and wp-admin to index.php as usual… but it still redirects and I get an error “The requested URL /index.php was not found on this server.”

Any help would be greatly appreciated. Ta.

Related posts