Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

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?

Answers

  • Options

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

  • Options

    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?

  • Options
    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

    There was an error rendering this rich post.

  • Options

    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.

  • Options
    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

    There was an error rendering this rich post.

  • Options

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

  • Options
    422422 Developer MVP
    edited February 2012

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

    There was an error rendering this rich post.

  • Options

    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

  • Options
    422422 Developer MVP

    i give up

    There was an error rendering this rich post.

  • Options

    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.

  • Options
    422422 Developer MVP
    edited July 2012

    Wonder why someone* marked it as abuse !

    There was an error rendering this rich post.

  • Options
    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 ;)

Sign In or Register to comment.