Forcing https
from client-side is deprecated, considering the connection has to be made to create a new connection. When a server redirects a client it is considered to be a redirect signal, which is safer because no information is shared between the client and the server (this is for keep-alive connections).
People who are naive of pages might have javascript disabled, and only allow it on certain paged. If this is the case, your redirect method will never apply to the website.
This will also never work if you are trying to work with an API, considering the client will never understand that you are trying to redirect them, the client is most likely to expected JSON, XML or YAML or any other storage syntax.