Is there a way to create a simple function that redirects every page of a site to another site?

I've Googled around but all the plugins / functions that I've found are only really meant for redirecting individual pages and not entire sites.

Any ideas?

  • Please rephrase your question in an edit and explain a bit more in detail what you are trying to do, what you already tried and where you are stuck. So far the question is too broad. Thanks. – kaiser Apr 23 '14 at 19:26

While the plugin might solve your problem you could try something direct with WordPress API:

add_action( 'template_redirect', 'wpse_142191_all_redirect' );
function wpse_142191_all_redirect() {
    if ( !is_user_logged_in() ) {
        wp_redirect( 'http://other-site.com', 301); 
            exit; //always die or exit after redirect

Be careful with it,this will redirect the whole site on the home page of other site. I added a condition, maybe you do not want to be redirect as a user of website.

| improve this answer | |
  • Why do you use template_redirect hook? – Krzysiek Dróżdż Apr 23 '14 at 17:29
  • because template_redirect is for redirect – JMau Apr 23 '14 at 17:58
  • Yes, I know. But it's fired pretty late in the process, so it's not very optimal solution... I'm pretty sure you can run same action in init hook (since you don't rely on query at all). – Krzysiek Dróżdż Apr 23 '14 at 18:09

You might be just best off doing a redirect with the htaccess file.

Redirect 301 / http://www.mynewwebsite.com

Further reading here: http://www.htaccessredirect.co.uk/

| improve this answer | |

Redirection plugin gives you simple GUI to define URL-based redirects (301 or 302) to your site. It supports regular expressions, so I think it is what you're looking for.

| improve this answer | |
  • Please add a short description to how the plugin works. Thanks – Pieter Goosen Apr 23 '14 at 17:25
  • @Peter Goosen: I did. This plugin provides redirects based on regular expressions. There is nothing more to add here. – Krzysiek Dróżdż Apr 23 '14 at 17:31
  • neither me. I kinda find this answer a good answer but I understood this is not allowed here – JMau Apr 23 '14 at 18:01
  • I know that you should not answer just with a link and so on. But I really don't know what else you can add in this case (this plugin does exactly what OP was asking, I guess). @PieterGoosen: Downvote is not a problem :) Although I'm really curious what is wrong with this answer in downvoter opinion... – Krzysiek Dróżdż Apr 23 '14 at 18:14

You could use wp_redirect but .htaccess is better in your case.

#Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
| 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.