using wp_redirect on multisite subfolder site (8 posts)

  1. lukelukeluke
    Posted 2 years ago #


    I have a multisite setup with subfolders. There are 3 sites installed which will use the same theme but in English, French and Dutch.

    I want to use wp_redirect in the header of the theme so that the user is redirected to one of the sites based on a cookie that is set when they click on a language option in a popup.

    The redirect works fine on the english site which has the path '/' but not on any of the other sites which have paths - '/fr/' and /'nl/'

    I've also tried redirecting using header("Location: http://example.com/"); and that doesn't work either.

    It literally does nothing!

    Is it because the sites are subfolders rather than sub directories?

    I'm stumped.

    Thanks for help


  2. What's the full redirect code you're using?

  3. lukelukeluke
    Posted 2 years ago #

    I've tried all sorts of variations of the following

    <?php wp_redirect( 'http://www.example.com', 301 ); exit; ?>

    It works on the main domain I.e. Http://subdomain.example.com

    But not on any of the other sites I.e Http://subdomain.example.com/fr

    The exit part of the code works as it stops any of the code after the statement executing.

    Any ideas?

  4. lukelukeluke
    Posted 2 years ago #

    Sorry, forgot to put code in tags.

  5. Sorry, let me rephrase.

    What's the WHOLE code you're using, to detect cookie, etc. Put it up on pastebin or github and link to it :) We may be able to debgu it that way.

  6. lukelukeluke
    Posted 2 years ago #

    Hello again,

    Well I've removed the cookie code and conditional statements for now to try and get the redirect work in the simplest way. So the that is the whole code. I've also tried it in the WP 2013 default theme. So if you imagine the header.php file in 2013 theme, then immediately below the head tag i placed

    <?php wp_redirect( 'http://www.example.com', 301 ); exit; ?>

    I've also tried using

    <?php header("Location: http://example.com/"); exit; ?>

    Which doesn't work either. This makes me think it is due to the subfolder setup on the multisite that stops it working. I am wondering if using subdomains instead would work?

    Thanks for your help


  7. No, it shouldn't matter.

    Are you sure you edited the right theme?

  8. lukelukeluke
    Posted 2 years ago #

    Yes quite sure. The "exit" code stops the rest of the page loading so you can tell.

    I set up a test multisite to try it on a clean install. Interestingly is doesn't even work on the root path ('/') http://test.lukeseall.co.uk/
    The second site is http://test.lukeseall.co.uk/fr

    So then I went back to the original site I am working on and cloned the root path site using NSclone. It works on the clone. i.e. ( Http://subdomain.example.com/clone)

    I have no idea why. There is something about the root path site that wp installation that makes it work... Very strange.


Topic Closed

This topic has been closed to new replies.

About this Topic