nuxt-community / redirect-module

No more cumbersome redirects for Nuxt 2!
MIT License
312 stars 17 forks source link

Redirect www to non-www with nuxt-redirect module #96

Closed Kaperskyguru closed 3 years ago

Kaperskyguru commented 3 years ago

Hello there,

Please how can I solve this problem with Nuxt-redirect

"Use 301 redirects to drive traffic to URLS with the same domain and sub domain (www and non-www subdomain)."

Move like redirecting www to non-www

Thanks

atinux commented 3 years ago

This is not possible currently with this module since it is using req.url.

I suggest you to directly handle this with a serverMiddleware.

Kaperskyguru commented 3 years ago

Wow. Do you have a way or example showing how to handle this with serverMiddleware?

atinux commented 3 years ago

We are using connect for serverMiddleware. You can take a look at https://mindthecode.com/blog/how-to-redirect-www-traffic-to-non-www-in-your-express-app/ but remember that res.redirect is only for Express, to do redirect in Connect (pure node.js http): https://stackoverflow.com/questions/22141137/response-redirect-in-connect

Kaperskyguru commented 3 years ago

Cool, But I was able to solve it with CloudFlare. I will check this out also.

https://support.cloudflare.com/hc/en-us/articles/200172286-How-do-I-perform-URL-forwarding-or-redirects-with-Cloudflare-

Thanks for your help.

atinux commented 3 years ago

Yes, CloudFlare is the best for this since it happens on the edge :fire: