2

One of our clients is having a problem with Google indexing incorrect URL's.

The shop templates are using something like...

{if segment_2 != "" AND segment_3 == "" AND segment_4 == ""}
    Parent Category List
    e.g. http://website.com/shop/parent/
{if:elseif segment_2 != "" AND segment_3 != "" AND segment_4 == ""}
    Child Category List
    e.g. http://website.com/shop/parent/child/
{if:elseif segment_2 != "" AND segment_3 != "" AND segment_4 != ""}
    Product
    e.g. http://website.com/shop/parent/child/product/
{/if}

But, they are getting URL's such as...

Which obviously don't exist and are picking up on the incorrect pagination amount etc.

Why would this happen, and how can this be stopped? E.g. how can we enable a 404 error for these kinds of pages.

The only way I've been able to fix it is for EE to check if the segments are a valid category or product, and then throw a message such as "No products found" or "Category doesn't exist"

But I just don't know how it's finding and generating these weird URLs. Obviously the "P1130" exists because it's showing ALL products, but that page shouldn't be accessible.

2
  • This is all in one template? Feb 7, 2014 at 14:32
  • is many ways how wierd url can be added into google. Random urls like gahhaiiuznyofiw.html can be used by google for testing you 404 error header. Instead of this your server is return back a full list of entries and spider is run forward. Just for sure you can tested links on your site with peacockmedia.co.uk/integrity
    – Max Lazar
    Feb 7, 2014 at 17:27

1 Answer 1

3

Try adding this within your channel:entries tag:

{exp:channel:entries ....}
  {if no_results}{redirect="404"}{/if}
{/exp:channel:entries}

This should trigger a 404 error on paginated pages that have no entries in them.

If you install Mo' Variables, you can enable an {if paginated} conditional for your templates. Then you can get a bit more specific and only trigger this 404 for paginated pages:

{exp:channel:entries ....}
  {if no_results}{if paginated}{redirect="404"}{/if}{/if}
{/exp:channel:entries}
2
  • Good shout. The only problem with this is that we're using super search to create a filter menu and sometimes it filters no results.
    – Jason Mayo
    Feb 7, 2014 at 14:15
  • See my edited answer, with an idea for that. Feb 7, 2014 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.