Search code examples
strapi

How to use the root route (/) as /admin in strapi


I want to open my subdomain admin.example.com and get directly to the admin login page, without the index.html page that comes before and tells me the page is in production environment, to improve usability to the customer and avoid something stupid like admin.example.com/admin.

Maybe I could do it with middlewares, but I'm clueless.

I'm using heroku.

Thank you


Solution

  • This is currently not supported.

    Currently we don't support serving the admin from the root, added as a feature request

    See https://github.com/strapi/strapi/issues/9302

    Workaround

    You can redirect / to /admin with a custom middleware.

    Create the middleware

    You may need to create the directory (mkdir -p middlewares/redirect/).

    // middlewares/redirect/index.js
    
    module.exports = () => {
      return {
        initialize() {
          strapi.router.get('/', (ctx) => {
            ctx.redirect(strapi.config.get('server.admin.url', '/admin'))
          })
        },
      };
    };
    

    Enable it

    // config/middleware.js
    
    module.exports = {
      settings: {
        redirect: {
          enabled: true
        }
      }
    }