ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Trapping bad URLs

September 02, 2011 12:50am

Subscribe [3]
  • #1 / Sep 02, 2011 12:50am

    Mark Wickens

    35 posts

    I’ve noticed that my site’s Google results contain many completely invalid URLs. For example:

    /weblog/Ben Johnson/All the abortion lies fit to print/Virtual Ayn Rand to run for U.S. presidency/Hollywood.com/P340

    This URL contains no valid template name and there is no entry with a url title of “Ben Johnson”. I have no idea how this happens, but that’s not my topic today! I just want to return a 404 for these invalid URLs so they don’t get indexed.

    I have tried putting this at the top of the index page for the weblog template group:

    {exp:channel:entries channel="mychannel" limit="1" require_entry="yes" }
    {if no_results}
    {redirect="404"}
    {/if}
    {/exp:channel:entries}

    This works great except for the slight problem that it returns a 404 for pagination (site.com/[weblog/]P20) and archive (site.com/[weblog/]2011/08) URLs.

    Perhaps I can resolve the issue with archives by using a different template instead of index.html (though I’d hate to break all my URLs—the site’s been up for almost 7 years). But I don’t see how to allow pagination to work.

    Can anyone point me in the right direction?

    Thanks,
    Mark

  • #2 / Sep 02, 2011 12:32pm

    Kevin Smith

    4784 posts

    Hi Mark,

    Have you taken a look at this guide: Guide to 404 Pages with ExpressionEngine? It aims to solve the very problem you’re facing, and I’d highly recommend it.

    Does that help?

  • #3 / Sep 02, 2011 3:47pm

    Mark Wickens

    35 posts

    Yes, that page was very helpful in resolving some of my issues with templates other than the index. I’ll take a closer look since you think it will help with the remaining problems. Thanks!

    Mark

  • #4 / Sep 02, 2011 4:08pm

    Sue Crocker

    26054 posts

    Sounds good, Mark. I’m going to mark this as resolved, please do post again if you run into any more issues.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases