Users running a non-download version of Vanilla (pulled from github), on branch release/2019.016 or master from the last 2 weeks should upgrade to release/2019.017 or latest master for security reasons. Downloaded official open sources releases are not affected.
Please upgrade here. These earlier versions are no longer being updated and have security issues.

How to return 404 for non-existing pages

edited February 2012 in Vanilla 2.0 - 2.8

In the current version of vanilla, I can access pages (ie. /P5, /P4) that don't have content, I want to return 404 for those pages. How can I make this?

Comments

  • maybe we can write something that return 404 if the result of the discussions array is empty

  • I thought about editing the class.discussioncontroller.php where I have the $ActualREsponses and do calculattion against the Comments.PerPage and get the Page number from the URL. For wrong page, return 404 via php. IS there any simpler way to do that?

  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    edited February 2012

    use hooks. look for a suitable Event in discussions Controller and hook into that event.

    like

    DiscussionsController_Render_Before($Sender) {
             $Offset = 0;
             $Limit = 10;
             $DiscussionModel = new DiscussionModel();
             $Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit, $Whereas);
             $CountDiscussions = count($DiscussionModel->Get($Offset, $Limit, $Whereas));
             $Sender->Data('Discussions', $Sender->DiscussionData);
             $Sender->SetData('CountDiscussions', $CountDiscussions);
    

    above hook is to display only 10 discussions without pagination as an example.

    you will have to look into whole code for discussionscontroller and hook it properly else it will be messed up

  • PLEASE EXPLAIN. I can even get to that page by using this URL "http://vanillaforums.org/discussion/18968/how-to-return-404-for-non-existing-pages/p5" ,which is wrong.

  • 422422 Developer MVP
    edited February 2012

    Can or cannot ? Forums use a thread id system

    This is common, the fancy pants titles are for your benefit.

    Reason is, so that you cannot impersonate another user .. And parse diff url to cheat the system. Try typing it in, url that is and change in browser the title words !

    Like this

    http://vanillaforums.org/discussion/18968/omg-i-hijacked-osama-bin-laden/p5

  • How do I get the page number from the URL, the one that shows P5, so I want the number 5 into my variable

  • 422422 Developer MVP
    edited February 2012

    That wasnt your original question though, your after pagination.
    Dashboard set comments per page

  • no, of course not, I need it for the code that I'm building, so I can check the data against the URL page number

  • this is the funniest one yet @422. Thx for the comic relief. Its an oldie but a goodie, and perhaps the funniest reponse I've seen on the forum.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    422UnderDog
  • 422422 Developer MVP
    edited July 2012

    Wonder why someone* marked it as abuse !

  • ToddTodd Chief Product Officer Vanilla Staff

    I see what the op is saying here. It would make for a cleaner experience. I would consider it low priority though since.

    1. Crawlers are highly unlikely to crawl off the end of the page list since there are no links.

    2. Returning a 404 error may make crawlers come back to the page less often which is bad for when there really is content.

    This is exactly the kind of feature that pull requests are made for though ;)

    UnderDog
Sign In or Register to comment.