302 Redirect
-
Hey there
i have an issue on this link https://dailymaverick.co.uk/section/declassified-uk/ whenever i click on an individual article, the site just reloads and i get a 302 redirect… i’m not sure how to resolve this, your help will be highly appreciated
ThanksThe page I need help with: [log in to see the link]
-
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
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
Yea, I’m sorry! I now see the issue. I guess you set the base path of
dailymaverick.co.ukto/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.Yes, these are my settings https://imgur.com/IrrsFoT please advice, how else can i can i do this?!
Thanks
If you simply want to redirect the home page to
/section/declassified-uk/, you could add the following to your theme’sfunctions.phpfile: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 6 years, 3 months ago by
Gustavo Straube. Reason: Fixed code
The snippet above was updated. I forgot to add it to inside an action.
I don’t think that’s gonna work cause… the main site is
https://dailymaverick.co.za/and we using the plugin to go tohttps://dailymaverick.co.uk/sections/declassified-uk/we using both sites, wont the above snippet redirecthttps://dailymaverick.co.za/to/section/declassified-uk/? keep in mind the.co.zaand.co.uk-
This reply was modified 6 years, 3 months ago by
Thulani Matshoba.
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.Hey @gustavostraube i’m afraid that didn’t work… it’s still redirecting to the same page 🙁
I’ve just checked the order WordPress fires the hooks (actions and filters) and it seems the action I suggested (
template_redirect) fires afterinit, which is used by the plugin. I hope the following will finally work as a replacement for theadd_actioncall in the previous snippet.add_action('init', 'force_section_redirect', 1);I’m sorry for this game of trial and error.
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);Have you removed the base path from the plugin settings? I mean, set the field blank and save.
-
This reply was modified 6 years, 3 months ago by
Gustavo Straube.
No, i still have the old settings i sent you earlier… should i remove the base path?
Yes, please.
I removed that base path, it’s still just reloading the page…
-
This reply was modified 6 years, 3 months ago by
The topic ‘302 Redirect’ is closed to new replies.