tags:

views:

16

answers:

2

When user enter the wrong url, the node js server will redirect to 404.html page, how can I implement this on nodejs. Do some search and it points me to expressjs ( looks like a nodejs wrapper ) but I want to write in nodejs.

Thanks for reading .

+1  A: 

The logic of determining a "wrong" url is specific to your application. It could be a simple file not found error or something else if you are doing a RESTful app. Once you've figured that out, sending a redirect is as simple as:

response.writeHead(302, {
  'Location': 'your/404/path.html'
  //add other headers here...
});
response.end();
Chetan Sastry
it doesn't show my 404 html page, maybe it's just show the header.
nXqd
Please read this - http://en.wikipedia.org/wiki/URL_redirection
Chetan Sastry