[Answer]-Port number getting stripped out of URL

1👍

What is happening is that your web server, as part of the login process is ‘redirecting’ your browser to a different web address. The problem is that the web address your browser is being redirected to doesn’t exist, because it is being redirected to the wrong web address. When you modify the web address, you are correcting this error.

Obviously the solution is to correct this problem in the code, so you are sent straight to the correct web address without you needing to correct this.

The solution depends on your code. It is worth looking at it with the following in mind.

Is there something like:

return HttpResponseRedirect('http://website/dir/')

in your code somewhere? This would need to be altered to include the port number, i.e

return HttpResponseRedirect('http://website:81/dir/')

Or, even better,

return HttpResponseRedirect('/dir/')

(This will mean that it won’t matter what port the server is on, because the redirect is ‘relative’. This would be the usual way to code this sort of thing.)

If a quick perusal of the source doesn’t cast any light, I would suggest that the next step would be to look in the access logs (and maybe error logs) from the web server, and look for ‘3xx’ type messages, probably ‘301’ and ‘302’ messages, and this may give you some clue as to what is happening, and where in the code.

Leave a comment