Redirect everything except /wp-admin and wp-login.php
Last Updated: May 10, 2019
Often, a client asks us to take down a site — either temporarily or permanently — but they still need access to their WordPress administrative panel.
As usual, there are lots of different ways to accomplish this; many SEO plugins allow you to create redirects, but require you to do so one post at a time. How tedious!
Fortunately, htaccess makes this simple, but I spent well over an hour googling for a solution that actually worked. Here’s what I’ve come up with.
Just make this edit to your .htaccess file, substituting new-site.com with the domain you want to redirect to. Place this code at the top of your file, above the # BEGIN WordPress
block.
RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} !^(.*)?wp-login\.php(.*)$ RewriteCond %{REQUEST_URI} !^(.*)?wp-admin$ RewriteCond %{REQUEST_URI} !^/(wp-includes/.*|wp-admin/.*|wp-content/.*)$ RewriteRule ^(.*)$ https://new-domain.com [R=301,L] # BEGIN WordPress ...
[caution_htaccess]
We hope this helps!