How to make 301 redirect in Node JS project with Express JS router?

I have Topic Search and Google and all search engines want to have 301 redirect, my project is set up on Heroku Cloud use node server and have problem whit redirect 301 ‘domain.com’ to ‘www.domain.com’…

Just RTFM :smiley:

Yes I foud this I came to this function " app.get(‘/’, function(request, response, next) { if(request.headers.host==“example.com”) { response.redirect(301, ‘example.com’); } else{ next(); } })" but it works only on the local server on my real server not …

Thank yet

what does request.headers.host contain on your real server?

Thank you decided problem and fixed :thumbsup:
I put http:// and host is only example.com and loop is not work
Have a nice day

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.