Nuxt Server apache2

Hello, I'm looking for help. I have an AWS EC2 server running on Apache 2, and I'd like to deploy a project on Nuxt 3. I have a problem: when I go to my domain/auth/login, it adds an /auth/login/ for 1 second, then removes it, and redirects me to my login form. In my curl, I get a 301 location: http://domain.com/auth/login/ Is this a Nuxt configuration or an Apache configuration?
3 Replies
kapa.ai
kapa.ai4mo ago
Hi @sullivan.mrr. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the knowledge sources, the behavior you’re describing—where visiting /auth/login results in a 301 redirect to /auth/login/—is most likely related to your Apache configuration, not Nuxt itself. One of the sources describes a similar setup where Apache is configured to redirect URLs that do not end with a trailing slash to the same URL with a trailing slash, using middleware or server configuration. Here’s an example of such middleware:
const redirect = (req, res, next) => {
const uri = req.url;
if (!uri.endsWith('/')) {
res.writeHead(301, { Location: uri + '/' });
res.end();
} else {
next();
}
};

export default redirect;
const redirect = (req, res, next) => {
const uri = req.url;
if (!uri.endsWith('/')) {
res.writeHead(301, { Location: uri + '/' });
res.end();
} else {
next();
}
};

export default redirect;
This kind of logic can also be implemented directly in Apache using rewrite rules or other configuration, and would result in the exact behavior you’re seeing: a 301 redirect from /auth/login to /auth/login/ before the page loads. This is not something Nuxt does by default, but rather a common pattern in web server configuration to enforce trailing slashes on URLs. If you want to avoid this redirect, you should review your Apache configuration and any middleware you may have added to your Nuxt project that enforces trailing slashes. In Nuxt, you can also control trailing slashes with the trailingSlash option in your nuxt.config.js, but the 301 redirect itself is typically handled by the web server (Apache in your case) rather than Nuxt directly Nuxtjs canonical URL are getting overridden on production. Summary:
The 301 redirect from /auth/login to /auth/login/ is most likely caused by your Apache configuration, not Nuxt. Check your Apache rewrite rules or any server middleware that enforces trailing slashes. Adjusting or removing those rules should resolve the issue. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@1010949826034274376> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
sullivan.mrr
sullivan.mrrOP4mo ago
It's good with : nitro: { prerender: { autoSubfolderIndex: false, } }

Did you find this page helpful?