Viewing 15 replies - 1 through 15 (of 23 total)
  • Plugin Contributor Gustavo Straube

    (@gustavostraube)

    Hello,

    I couldn’t reproduce the redirect you mentioned. Accessing that URL gives me a 200 status code, check this out: https://imgur.com/a/LIvNrEC.

    Gustavo

    Thread Starter Thulani Matshoba

    (@skinnyninjah)

    Hey @gustavostraube, thanks for a prompt reply… the issue is when you click any article on that url, it just reloads the page instead of going to that particular article

    Please let me know if this makes sense. Thanks

    Plugin Contributor Gustavo Straube

    (@gustavostraube)

    Yea, I’m sorry! I now see the issue. I guess you set the base path of dailymaverick.co.uk to /section/declassified-uk/. Am I right? If so, that’s causing the redirect.

    When setting a base path, only URLs under that path will be available. Otherwise, they’ll redirect to the base path. Since article URLs start with /article/, they don’t work. You have to omit the base path to get it working.

    Thread Starter Thulani Matshoba

    (@skinnyninjah)

    Yes, these are my settings https://imgur.com/IrrsFoT please advice, how else can i can i do this?!

    Thanks

    Plugin Contributor Gustavo Straube

    (@gustavostraube)

    If you simply want to redirect the home page to /section/declassified-uk/, you could add the following to your theme’s functions.php file:

    function force_section_redirect() {
        if (is_home() || is_front_page()) {
            wp_redirect(home_url('/section/declassified-uk/'));
            exit;
        }
    }
    
    add_action('template_redirect', 'force_section_redirect');

    Also, leave the base path in the plugin settings empty.

    Let me know how it goes.

    • This reply was modified 4 years, 9 months ago by Gustavo Straube. Reason: Fixed code
    Plugin Contributor Gustavo Straube

    (@gustavostraube)

    The snippet above was updated. I forgot to add it to inside an action.

    Thread Starter Thulani Matshoba

    (@skinnyninjah)

    I don’t think that’s gonna work cause… the main site is https://dailymaverick.co.za/ and we using the plugin to go to https://dailymaverick.co.uk/sections/declassified-uk/ we using both sites, wont the above snippet redirect https://dailymaverick.co.za/ to /section/declassified-uk/ ? keep in mind the .co.za and .co.uk

    Plugin Contributor Gustavo Straube

    (@gustavostraube)

    Got you. Try this instead:

    function force_section_redirect() {
        if (MULTIPLE_DOMAIN_DOMAIN === 'dailymaverick.co.uk' && (is_home() || is_front_page())) {
            wp_redirect(home_url('/section/declassified-uk/'));
            exit;
        }
    }
    
    add_action('template_redirect', 'force_section_redirect');

    This way, it’ll only redirect when on dailymaverick.co.uk.

    Thread Starter Thulani Matshoba

    (@skinnyninjah)

    Hey @gustavostraube i’m afraid that didn’t work… it’s still redirecting to the same page ??

    Plugin Contributor Gustavo Straube

    (@gustavostraube)

    I’ve just checked the order WordPress fires the hooks (actions and filters) and it seems the action I suggested (template_redirect) fires after init, which is used by the plugin. I hope the following will finally work as a replacement for the add_action call in the previous snippet.

    add_action('init', 'force_section_redirect', 1);

    I’m sorry for this game of trial and error.

    Thread Starter Thulani Matshoba

    (@skinnyninjah)

    No its ok man i understand, i appreciate all your help… i’m afraid that didn’t work also though

    function force_section_redirect() {
        if (MULTIPLE_DOMAIN_DOMAIN === 'dailymaverick.co.uk' && (is_home() || is_front_page())) {
            wp_redirect(home_url('/section/declassified-uk/'));
            exit;
        }
    }
    add_action('init', 'force_section_redirect', 1);
    Plugin Contributor Gustavo Straube

    (@gustavostraube)

    Have you removed the base path from the plugin settings? I mean, set the field blank and save.

    Thread Starter Thulani Matshoba

    (@skinnyninjah)

    No, i still have the old settings i sent you earlier… should i remove the base path?

    Plugin Contributor Gustavo Straube

    (@gustavostraube)

    Yes, please.

    Thread Starter Thulani Matshoba

    (@skinnyninjah)

    I removed that base path, it’s still just reloading the page…

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘302 Redirect’ is closed to new replies.