Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
405 B
1
Indexable
Never
##server/middleware/wwwRedirects.js

export default defineEventHandler((event) => {
  const config = useRuntimeConfig();
  const host = getRequestHeader(event, "host");
  const url = event.node.req.url;
  const env = config.enviroment;

  if (env === "production" && host.startsWith("www.")) {
    const nonWWWHost = host.substring(4);
    sendRedirect(event, `https://${nonWWWHost}${url}`, 301);
  }
});
Leave a Comment