• @davidmatthew Would be cool to have a feature to add links that have to be skipped on redirection. At the moment I need core sitemap to be accessible to use on app side in robots.txt

    Here’s a dirty way to do that.

    /**
     * The redirect function.
     */
    	public function redirect() {
    
    		if ( ! is_admin() && ! str_contains($_SERVER['REQUEST_URI'], 'wp-sitemap')) {
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author David Matthew

    (@davidmatthew)

    @brynzovskii Thanks for the suggestion – I’ll update the plugin to include this as an option! Once done (hopefully can get some time this weekend) I’ll reply back here and let you know. 🙂

    Thread Starter brynzovskii

    (@brynzovskii)

    Sounds cool. Thank you!

    Plugin Author David Matthew

    (@davidmatthew)

    Hi @brynzovskii, just to update you, I’m using the below code at the moment and it works for sitemaps generated by plugins like Slim SEO (the one I use) but for some reason I haven’t yet figured out, it’s not working for WordPress-generated sitemaps.

    
    /**
     * The redirect function.
     */
    public function redirect() {
    
        $options = get_option( 'guillotheme_settings' );
    
        if ( $options['skip_sitemap'] !== null ) {
    
            // This should catch anything containing both 'sitemap' and '.xml'
            $regex = "/^.*?\bsitemap\b.*?\bxml\b.*?$/";
    
            $req = esc_url( $_SERVER['REQUEST_URI']);
    
            if ( preg_match( $regex, $req ) ) return;
    
        }
    
        if ( ! is_admin() ) {
        ...
    

    As you can see I’m using a regex to catch any kind of sitemaps (as I figured they all must have ‘sitemap’ and ‘.xml’ in common) and comparing with the request URI using preg_match(). I didn’t go with str_contains() as it’s supported only in PHP 8+.

    Could you maybe try this code on your site (or a variation of it – ignore the $options['skip_sitemap'] bit) to see if it’s something server-related on my end? If you can’t it’s ok, I’ll try to track down whatever it is that’s going wrong. May not get the time in the next few weeks though as I’ll be away.

    • This reply was modified 2 years, 6 months ago by David Matthew.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Redirection should skip wp-sitemap.xml’ is closed to new replies.