I'm using a customized version of the vhost
connect/express middleware and inside it I check for the www
subdomain. If I find that subdomain, then I redirect to the host + path without the www
. So for example, if I go to www.google.com
I want to redirect to google.com
. I call:
if (subdomain === "www") {
res.redirect(req.headers.host.split('.').slice(1).join('.') + req.url);
}
However, this redirects me to: www.google.comgoogle.com
as it appends the new url to the original one. Why is it doing this?