0

I am trying to get the home page only (index) of specific blogs in my multisite instance to redirect to another URL entirely. I want people to be able to resolve links to individual pages/articles, just the home page will redirect.

Not all the sub-sites in multisite,just 1 or 2.

The intent is to basically 'archive' the site, but move the index page to a new URL

How can I specify specific blogs on the stack? Is this better done as a header redirect? Can it be done in htaccess? There doesnt seem to be an individual dir for each sub-site with its respective htaccess, otherwise it would be pretty straightforward. Target the IDs of the blogs?

Something like WP_Maintenance comes close but only redirects once logged in. I cant seem to find a plugin that does this specifically either, but would be happy to make one if it could be hooked in this fashion.

Im familiar with htaccess, but how can I target specific blogs? I have found examples and posts on several issues that are close, but not this exactly. Im sure this is something dreadfully simple that Im overlooking.

Most importantly Im looking for a 'Wordpress safe' answer that won't have unintended consequences.

1

You can detect if you're on the front page of a given site with is_front_page(). You can use the init hook to do a wp_redirect() to any absolute URI you want.

add_action( 'init', 'wpse182623_redirect_home_page_only' );
function wpse182623_redirect_home_page_only() {
    if( is_front_page() ) {
        wp_redirect( 'http://example.com/some-other-page/' );
        exit;
    }
}

Put this into a plugin and activate that plugin on any sites where you need the front page to redirect elsewhere.


Reference

| improve this answer | |
  • for posterity, this doesnt trigger a 'headers already sent' by PHP then? This seems terribly obvious. Thanks for the info. – roberthuttinger Apr 2 '15 at 17:45
  • 1
    From the init docs: "Fires after WordPress has finished loading but before any headers are sent." So I think it should be fine, but I haven't tested it to be 100% sure. – Pat J Apr 2 '15 at 18:09

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.