search

Home  >  Q&A  >  body text

How to redirect if subdirectory contains hash Nuxt?

At the request of SEO experts, I need to implement the following functions. I have to redirect if the link contains capital letters. For example https://domain.com/#Contacts ==> https//domain.com/#contacts.

In Nuxt, I do this by creating a function on the server.js file in the middleware folder.

But if the path contains hash(#), it will not work

export default function (req, res, next) {
    const url = req.url;

    if (url !== url.toLowerCase()) {
        res.writeHead(301, { Location: url.toLowerCase() });
        res.end()
    } else {
        next();
    }
}

I would be grateful if you answer or provide help

P粉277305212P粉277305212508 days ago644

reply all(1)I'll reply

  • P粉964682904

    P粉9646829042023-09-08 09:31:42

    The hashed part (Fragment Identifier) is never sent to the server through the browser connection, so your attempt to use a redirect is impossible.

    You can access them client-side, but I don't think that does any SEO good.

    reply
    0
  • Cancelreply