• Resolved Nazmul Akanda

    (@ampninja)


    Please check my website woo-commerce product:

    6×12 Enclosed Trailer

    From RankMath admin panel plugin settings:
    General-Settings->WooCommerce

    I have enabled: Remove base so all my products URL showing without /product/
    2019-12-30_2230

    But this is causing 404 from source code
    2019-12-30_2240

    please check <link rel=”alternate” URLs

    
    https://www.anvilcargotrailers.com/wp-json/oembed/1.0/embed?url=https%3A%2F%2Fwww.anvilcargotrailers.com%2F6x12-enclosed-trailer%2F
    
    https://www.anvilcargotrailers.com/wp-json/oembed/1.0/embed?url=https%3A%2F%2Fwww.anvilcargotrailers.com%2F6x12-enclosed-trailer%2F
    

    you can see both of these errors generating 404 error

    Thanks
    Nazmul

    • This topic was modified 4 years, 11 months ago by Nazmul Akanda.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Rank Math

    (@rankmath)

    Hello @ampninja

    Thank you for contacting the support and sincere apologies for the delayed response.

    Please add the following filter to your theme’s functions.php file:

    add_filter( 'oembed_request_post_id', function( $post_id, $url ){
    	if ( $post_id ) {
    		return $post_id;
    	}
    
    	$parsed_url = wp_parse_url( $url ); // Parse URL
    	echo $slug = substr($parsed_url['path'], 1 );
    	$post = get_page_by_path( $slug, OBJECT, 'product' );
    	if ( ! is_wp_error( $post ) && ! empty( $post ) ) {
    		$post_id = $post->ID;
    	}
    	return $post_id;
    }, 10, 2);

    That should resolve the issue. If it doesn’t, please let us know

    I had these errors too. And the code mentioned earlier have helped. But there is still an error on <link rel=”alternate” type=”text/xml+oembed”

    https://prnt.sc/szn010

    Plugin Author Rank Math

    (@rankmath)

    Hello @sverger

    Can you please try the following code instead?

    add_filter( 'oembed_request_post_id', function( $post_id, $url ){
    	if ( $post_id ) {
    		return $post_id;
    	}
    	$parsed_url = wp_parse_url( $url ); // Parse URL
    	$slug = substr( $parsed_url['path'], 1 );
    	$post = get_page_by_path( $slug, OBJECT, 'product' );
    	if ( ! is_wp_error( $post ) && ! empty( $post ) ) {
    		$post_id = $post->ID;
    	}
    	return $post_id;
    }, 10, 2);

    Hope that helps. Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Removing Base From Product generating 404 urls in source’ is closed to new replies.