Search code examples
http-redirectmasonite

How to do Permanent Redirect in Masonite


I can redirect the user, it works but it has 302 status, how I can redirect a user and add 301 so it will be permanent redirect?

request.redirect('/dashboard') 

Solution

  • You can add the status you need as a status parameter:

    request.redirect('/dashboard', status=301)
    

    If using Masonite 2.2+ you can also create a Redirect route:

    from masonite.routes import Redirect
    
    ROUTES = [
        Redirect('/from', '/to', status=301)
    ]