1

I have a view in drupal 7 with no contextual filters at all set.

Let's say it is a simple list of nodes of the type "item" and that the url is http://example.com/listofitems

I also have pathauto patterns set for the individual nodes. So if an item titled "my item" is created the url would be http://example.com/listofitems/my-item This is important to know because I don't want to set another view for the path listofitems/%.

Given that no view or URL alias exists for listofitems/foo I expected that this URL would give a 404 error: http://example.com/listofitems/foo

Instead it shows the full view with no errors. This is confusing and bad for SEO. If a bot hits http://example.com/listofitems/foo/bar/foo/bar/foo/bar/blahblahblahblah they should get a 404 message. Or better yet, they could get a 301 redirect to the main view url. In any case, they should not be allowed to stay on the non-existant URL and see the view with no errors.

How can I accomplish this? Is there a trick I'm missing or a reason that this is the default behavior?

3 Answers 3

5

The problem lies in Drupal's menu system, which for the most part asserts itself as a safety mechanism, so if you or someone else mis-spells a URL it will give you the next best option.

Admin Menu Example

admin/structure/blocks = Manage Blocks Page

admin/structure/blockss = Structure Page

Drupal does this so it won't "disrupt" the user-experience, but it can also be a confusing if you don't know what just happened.

It's generally there to prevent human error and other problems that arise when managing a live website.

The Options

  1. Keep the default set, so users are accommodated and instead focus on structuring the robots.txt (and perhaps .htaccess) file correctly, so you can let Search Engines know what's happening.

  2. Look into the Rules and Context contributed modules to see if you can create a solution using those interfaces. You may or may not be able to find a solution there, but it might be a good start.

  3. Create a module, which will handle non-existent URL's and correctly reroute them to 404 page.

2
  • Thanks for the feedback, and for helping identify the menu system as the culprit. I was hoping it would be simpler than this... ah, well. Feb 20, 2015 at 4:10
  • drupal.org/node/432384 - Clearly this is an ongoing systemic issue with Drupal that doesn't have an easy answer. Feb 20, 2015 at 15:41
0

Check the box to specify valdation criteria in the settings for the contextual filter. If one of the basic options works, great, or worst case, you can choose "PHP Code" and have it do whatever you want.

2
  • The question states that I do not want to use the views contextual filter at all. Feb 20, 2015 at 4:07
  • Right, but you might set one up so that it always validates wrong, yielding a 404, redirect, or whatever you like.
    – Andie Hunt
    Feb 20, 2015 at 5:12
0

I think you should be able to get this to work by using the Rules module (suggested as one of the options in another answer also already).

Depending on how the format of your URLs look like, you may want to also use the Rules URL Argument module. Here is a quote about it (from its project page):

... provides two rules conditions based on URL arguments:

  • check if a URL argument is present.
  • compare the value of an URL argument.

It also provides an action that makes the value of an URL argument available as new variable to Rules.

The newly provided Rules actions and conditions can be found under the "URL Argument" conditions and actions groups in the rule configuration interface.

For more details, refer to my answer to the question "How to use the Rules module to implement a custom redirect for an outdated URL?".

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.