Giter VIP home page Giter VIP logo

Comments (6)

acicali avatar acicali commented on May 19, 2024 2

I advise against redirection as a means to serve 404 responses. It breaks the web. Perhaps under certain conditions, an action by another request might make that URL no longer a 404 (e.g. user created CMS pages). By redirecting, you've taken away the user's ability to reload the page and get the expected response. Instead, they'll have to go back a page.

from router.

uvulpos avatar uvulpos commented on May 19, 2024 2

I missed that Issue sorry → #144 #145
With my Pull Request, you could say:

$router->set404('ErrorController@notFoundWebsite');
$router->set404('/api(/.*)?', 'ErrorController@notFoundApi');

from router.

bramus avatar bramus commented on May 19, 2024

I'll gladly accept a PR that provides this.

from router.

acicali avatar acicali commented on May 19, 2024

This can be accomplished with a very minor change to the beginning of Router->mount()

    public function mount($baseRoute, $fn)
    {
        // Bail if this mount does not match the URI
        if(strpos($this->getCurrentUri(), $baseRoute) !== 0){
            return false;
        }

        // ...

This change may also resolve #55 since it stops arbitrary code from being run within the mount()'d callable when the route does not match. It is not compatible with #75, but that feature does not exist anyway.

from router.

floralsystems avatar floralsystems commented on May 19, 2024

This solution means that calls to $router->set404() after $router->mount() would overwrite the mounted 404. It's not ideal.

from router.

sumanthratna avatar sumanthratna commented on May 19, 2024

Obviously not the best solution, but this could work:

  • create a GET route for /404, and this route should accept a get parameter giving the path of the initially requested page
  • whenever the user requests an invalid page, use header or another method to redirect to /404?route=[THE ROUTE THE USER REQUESTED]
  • when dealing with the GET route to /404, you can use a simple if statement to see if the route GET parameter starts with api or not
  • show different 404 pages based on the value of the route variable

from router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.