• Resolved Vlad Kobrenko

    (@kobrenko)


    Hello! Thanks so much for the great plugin. It works well, but today it encountered the following error:
    I added the following code in the function.php

    function custom_rewrite_basic() {
    	add_rewrite_tag('%blog_category%','([^&]+)');
    	add_rewrite_rule('^blog/category/([0-9a-zA-Z+-]+)/?', 'index.php?pagename=blog&blog_category=$matches[1]', 'top');
    }
    
    add_action('init', 'custom_rewrite_basic', 1);

    It works when the plugin is disabled. For example, I can go on URL: “www.site.com/blog/category/my-cat” and it will work.

    But when the plugin is enabled, during a visit to this link, redirecting to “www.site.com/blog” occurs (screenshot)

    P.S.
    Blog – this is the real page that exists on the site.

    Please tell me what could be the problem..

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi @kobrenko,

    could you try to disable canonical redirect in Permalink Manager settings?

    Best regards,
    Maciej

    Thread Starter Vlad Kobrenko

    (@kobrenko)

    @mbis, thanks for the answer.
    I use the free version of the plugin, so I do not have this option

    Plugin Author Maciej Bis

    (@mbis)

    I see, but this option is also included in free version of plugin:
    https://prntscr.com/maom1f

    Thread Starter Vlad Kobrenko

    (@kobrenko)

    @mbis , thank you. I turned off the “Redirect” option and now everything works.

    Tell me, and if I do not want to disable redirection in general for links (https://prnt.sc/maosgw), but I want to disable only for a specific page.
    Can I do something like that? Maybe there are some hooks?

    Plugin Author Maciej Bis

    (@mbis)

    Hi @kobrenko,

    I would recommend to hook into “wp” action and define “do_not_redirect” query var, eg.

    function pm_stop_redirect() {
    	global $wp_query;
    
    	if( ... ) {
    		$wp_query->query_vars['do_not_redirect'] = 1;
    	}
    }
    add_action('wp', 'pm_stop_redirect', 0);

    Best regards,
    Maciej

    Thread Starter Vlad Kobrenko

    (@kobrenko)

    @mbis, exactly what is needed! Thank you very much for the quality support ??

    Thread Starter Vlad Kobrenko

    (@kobrenko)

    Hi @mbis!

    Can you please tell me if I can disable the option ‘Canonical redirect’ in this way?

    function pm_stop_canonical_redirect() {
    	global $wp_query;
    
    	$wp_query->query_vars['...'] = 1;
    }
    add_action('wp', 'pm_stop_canonical_redirect', 0);
    Plugin Author Maciej Bis

    (@mbis)

    Hi @kobrenko,

    if you would like to disable canonical redirect, you should use this code:

    function pm_stop_canonical_redirect() {
    	remove_action('template_redirect', 'wp_old_slug_redirect');
     	remove_action('template_redirect', 'redirect_canonical');
     	add_filter('wpml_is_redirected', '__return_false', 99, 2);
     	add_filter('pll_check_canonical_url', '__return_false', 99, 2);
    }
    add_action('wp', 'pm_stop_canonical_redirect', 0);
    Thread Starter Vlad Kobrenko

    (@kobrenko)

    @mbis, thank you!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Redirect when visiting a page with a custom rewrite_rule’ is closed to new replies.