0

With .htaccess I'm trying to redirect all traffic away from a WordPress site, except traffic to wp-admin.

The goal is to redirect all traffic away from the site, but retain admin access.

I'm using .htaccess to do this, and it's working to an extent. But when trying to access wp-admin I get an internal server error.

The site is on a subdomain and this is my current code:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} subdomain\.oldsite\.co\.uk$ [NC]
    RewriteCond %{REQUEST_URI} !^/wp-admin [NC]
    RewriteRule ^(.*)$ http://www.newsite.co.uk/$1 [R=301,L]

I'd be grateful for any insights.

  • Do you mean error 500? They are very unspecific from outside, you would have to first figure out actual underlying reason for it. – Rarst Sep 17 '16 at 17:28
  • Yes indeed, error 500. – Dvaeer Sep 17 '16 at 18:06
  • @Dvaeer From your code, it looks like you want all traffic from subdomain.oldsite.co.uk to redirect to www.newsite.co.uk except when someone visits subdomain.oldsite.co.uk/wp-admin? – Ethan Jinks O'Sullivan Sep 17 '16 at 18:17
  • That's right @ethan-jinks-osullivan. And the redirection part works, but the exception doesn't. – Dvaeer Sep 17 '16 at 18:33
  • I've tried various things, but not getting a satisfactory result. So now doing this a different wa. Will post as an answer. Thank you everyone - learned a few things. – Dvaeer Sep 19 '16 at 8:51
1

Answering my own question for future reference. I couldn't get a redirect to work with .htaccess, but found some helpful troubleshooting suggestions, mainly this one: https://stackoverflow.com/a/14116956/3218102.

I ended up doing this with a modification to header.php and the functions wp_redirect and is_admin.

This is the code I added to the top of header.php:

<?php 
// Redirect everyone to new URL, except admin
if ( ! is_admin() ) {
     wp_redirect( 'http://www.newsite.co.uk/', 301 ); 
     exit;
}
?>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.