Problems with list and detail urls and Google

  • Hi,

    I created a two page list and detail on a project some time ago.

    The person running the SEO on the site is picking up urls that don't exist in Google search console.

    I have an .htaccess rule as follows for the list/detail setup, building-detail.php being the "detail" page. This all works as expected, tidying the urls so that they take the form /properties/property-name

    1. RewriteRule ^properties/([a-zA-Z0-9-/]+)$ /building-detail.php?s=$1 [L]

    The issue I am having is that any url entered after /properties returns a 200 OK response. e.g. /properties/whatever

    Is they any way to return a 404 for "detail" pages that don't exist?

  • drewm

    Approved the thread.
  • Hi Andy,

    Yes, you can control this. Perch gives you control over things, so a lot of the times when you want something to behave in a certain way you would be responsible for that; not Perch.

    Assuming you are using a multiple-item region, it means you are using perch_contetn_custom() to fetch and output the item on the detail page. Perhaps something like this:

    1. perch_content_custom('Properties', [
    2. 'filter' => 'slug',
    3. 'match' => 'eq',
    4. 'value' => perch_get('s'),
    5. ]);

    This only handles the retrieving of the item and outputting it. If on this page "not finding an item" means 404, you need to implement this behaviour as Perch does not assume how you want to handle this.

    At the top of your PHP page, after your Perch runtime include and before you output anything to the page is the ideal place to handle this:

    If you are using Runway, you can use:

    1. if(!$item_html) {
    2. PerchSystem::use_error_page(404);
    3. exit;
    4. }