Closed (fixed)
Project:
Views (for Drupal 7)
Version:
5.x-1.6
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
28 Sep 2007 at 00:44 UTC
Updated:
2 Apr 2012 at 07:17 UTC
I have a view, lets say at "/apples" that lists all apples. It accepts no arguments.
Now if a user enters "/apples/1" or "/apples/bananas" it still shows the entire apples list.
Is there any way to stop this from happening?
One reason I can think of is that I have moved a few other nodes around eg "/apples/delcious" which are unrelated to the view. But search engines still list "/apples/delicious" as a valid page and therefore is likely to be regarded as a duplicate of "/apples".
Comments
Comment #1
merlinofchaos commentedThis is standard drupal behavior. You can set something up in the PHP Argument Code that will do this, though:
The problem here is, though, that drupal_not_found() may not actually work quite right. So you may actually have to get tricker, and if you have no arguments, *add* a views argument which will 404. I leave how to do this as an exercise. (but if you want some tips, create a view with such an argument, export the view, and grab just the arguments portion of the code).
Comment #2
FWE commentedHello,
I have begun working with Views today and have stumbled across the same issue.
Due to my inexperience - I first thought this to be a problem with my configuration/settings and spent a great deal of time trying to sort this out. However, after reading this post I am thinking that this is the default behavior for Drupal & Views - is this the case?
I ask as after my "discovery" I visited many sites to test this out. It appears that with most sites using Views one can add something like "asdfqwerty" at some point into the URL and have the designated view display - e.g. (using the example above):
/apples <<< lists all apples
/apples/asdfqwerty <<< also lists all apples
If this is supposed to happen - I would love to know so that I have a better overall understanding. Could this potentially lead to penalties regarding SEO?
Thank you for any help you can provide!
Comment #3
merlinofchaos commentedGenerally Drupal absorbs extra arguments. Try visiting node/1/gargleblaster on your site (assuming node/1 actually exists) and a variety of other (non-aliased) links. It's a Drupal thing.
In Views you can often add another argument, set the default action to ignore, and if it's present make sure it conflicts nicely with the existing arguments. That'll 404 you if that's what you want.
So far as I know this won't create SEO penalties either way because you're not exposing multiple links to the same content.
Comment #4
FWE commentedThank you merlinofchaos - I really appreciate your help!
Now that I understand that this is how Drupal works - I feel much more confident with what I am doing. I will definitely follow your suggestions regarding 404 pages - but it sounds like it might be unnecessary. Best wishes and thank you again for your your comments.
Comment #6
liquidcms commentedI am sure Eric's solution is better.. but couldn't get it to work (plus things like "set the default action to ignore" didn't make any sense).
This is what worked for me.
i added arg for NID with default set as 404. Then i set wildcard to "all" and added this code:
also, this post has more info on push in core to get this fixed: http://drupal.org/node/90780 but i have 5.10 at the moment and still busted. I think post mainly deals with /node arg handling; but wasn't sure.
Comment #7
FranCarstens commentedI realise this post is a bazillion years old, but I've run into a problem with one of my customers who still uses Views 1 on D5.
Because Views provides a page for empty arguments the site is not PCI compliant (very watered down explanation). Example:
domain.com/shop/dress -> valid url, opens page.
domain.com/shop/admin-console -> invalid url, opens page instead of 404. This causes the PCI validation to fail.
I've tried the #6 options, but that only works to validate the domain.com/shop and 404's all the other pages (domain/shop/page), including valid ones.
Is there a solution to this?
Comment #8
mr.j commentedHa. I googled this and found an issue that I wrote years ago. This is still a problem in 6.x and probably 7.x (haven't used it yet). What I ended up doing in 6.x was this;
Add an argument to your view such as Node: nid. Then in the validation selector, select PHP code and just put
return FALSE;in the validation box. Set the action to take to return a 404 if the argument doesn't validate and it will always fail validation if there is an extra argument that you don't want.