• Hi,

    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: https://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

    Luke

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    What’s the full redirect code you’re using?

    Thread Starter lukelukeluke

    (@lukelukeluke)

    I’ve tried all sorts of variations of the following

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

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

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

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

    Any ideas?

    Thread Starter lukelukeluke

    (@lukelukeluke)

    Sorry, forgot to put code in tags.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    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.

    Thread Starter lukelukeluke

    (@lukelukeluke)

    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( 'https://www.example.com', 301 ); exit; ?>

    I’ve also tried using

    <?php header("Location: https://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

    Luke

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    No, it shouldn’t matter.

    Are you sure you edited the right theme?

    Thread Starter lukelukeluke

    (@lukelukeluke)

    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 (‘/’) https://test.lukeseall.co.uk/
    The second site is https://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. ( https://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.

    Luke

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘using wp_redirect on multisite subfolder site’ is closed to new replies.