Why I get “301” Moved permanently when I set “/manage” as path

When I set “/manage” as path :

router.get("/manage",function(req,res,next){
	var option = {
		root : path.dirname(__dirname),
	}
	res.sendFile("build/manage.html",option);
})

and use it in my app.js , but when I open localhost:3000/manage , I got a status “301 Moved permanently” . And I was redirected to localhost:3000/manage/

However , if I just change /manage to other path , like “/index”.

router.get("/index",function(req,res,next){
	var option = {
		root : path.dirname(__dirname),
	}
	res.sendFile("build/manage.html",option);
})

Then also open localhost:3000/index , I just got status “200 OK ” , and was NOT redirected to localhost:3000/index/

Here is the status “301 Moved permanently” response header :

HTTP/1.1 301 Moved Permanentl
X-Powered-By: Express
Content-Type: text/html; charset=UTF-8
Content-Length: 171
Content-Security-Policy: default-src ‘self’
X-Content-Type-Options: nosniff
Location: /manage/
Date: Tue, 12 Dec 2017 15:23:38 GMT
Connection: keep-alive

I think that’s very strange ,and wonder why .
Thanks for reading !

Author: Fantashit

2 thoughts on “Why I get “301” Moved permanently when I set “/manage” as path

  1. Could it be that you have a static middleware before that is redirecting /manage to /manage/ since there is a directory called manage?

  2. @vanesyan Thanks for taking time to reply !

    I didn’t know strict parameter , and now I know it , thank you. The problem is what LinusU said , I have a static middleware , and have created a directory called manage in static directory . Like this :

    └──build
         ├── manage
                └── somefiles
         ├── otherfiles.js/css/png
    

    @LinusU Thank you for taking time to reply ,too!

    I have checked my code , and found I have created a directory called manage which is used for testing by coincidence , and forgot to delete it . After I delete it , the problem is solved . Thank you so much!

Comments are closed.