When you need to get a 404... but instead you get a View.. what do you do?

The site shows a View profile of bloggers and lives at the url "/blogs".  Unfortunately, this save View became visible at "/blogs/{anyrandomword}".  This was not the desired result.  To further this specific instance, I realized that my path for the teaser view of each bloggers' post's was at the dynamic url of "/blogs/{username}".

My goal was to preserve my View of each bloggers' profile at "/blogs", allow the user teasers at "/blogs/{username}, and ensure that any random text or characters after "/blogs" would go to a 404 page.
<!--break-->
After a little deducing, I was able to make a small change to my View settings, that enabled me to not change any paths, not re-write any views, and now that I know where to do it, I will share so that it will only take you a minute to complete.

<h3>Here's what I did</h3>
within the View you want to add an argument.
the argument that I used was Global:NULL

The first setting is to make sure display all is enabled.

I then set the php code within that argument to,

<code>
arg(1)==NULL;
</code>

Finally, I set the action to take if argument does not validate to:
Hide view / Page not found (404)

These settings tells the view that there can be no argument after the /blogs, and if there is... five me a 404 page.  And since the blog module is handling the blots/{username}, it doesn't get sent to the view :)

Comments

3

http://drupal.org/project/views404

I would like to understand why this is only a case for views,see this as example http://blogthingee.com/node/1/123/123/123/123

Because the paths are dynamic, they can appear on all kinds of places. It really depends on how/where you are concerned about it. In some cases content is better than a 404 page. IMHO

Add new comment

By submitting this form, you accept the Mollom privacy policy.