Quick and easy Wordpress redirection to external URL
Redirect non logged-in visitors to a Wordpress site to another external URL.
I recently built a website for a client who had an existing site on another domain. While the new website was being setup, they wanted any visitors to go straight to the existing site instead of seeing a coming soon page.
There are plenty of Under Construction, Maintenance and Coming Soon plugins for Wordpress. These all display a page that says Under Construction, Coming Soon or similar, but not many will automatically redirect a visitor to another domain.
This quick solution can be implemented in a couple of minutes, and will allow access to the whole website to all users who are logged in, and send everyone else to the alternative domain.
The setup
Create a blank html file named redirect.html (or whatever you prefer) in the root directory of your domain
Add this code to your functions.php:
if(!is_user_logged_in() && $pagenow != ‘wp-login.php’) {wp_redirect( ‘/redirect.html’, 302 );}
From the control panel for your web server, set up a redirect for the file yourdomain.com/redirect.html to the external URL you want to send non logged-in visitors to.
To turn off, remove the function from your functions.php file and the redirect from your web server