7

Traditionally in php a .htaccess file is used to redirect http to https.

Is there a better way in VueJS without using .htaccess?

Ivan Lim
  • 179
  • 2
  • 7
  • You typically would do this at the server level. Why can't you use `.htaccess`? – ceejayoz Oct 12 '17 at 14:17
  • Not sure using .htaccess is a best practice with VueJS. I have researched other VueJS projects on github, so far I have not found one that contains a .htaccess file in the repo. – Ivan Lim Oct 12 '17 at 14:22
  • Using `.htaccess` (or better yet, the server config file itself) is absolutely the right way to handle this. They're not in the various Vue.js repos because not everyone uses Apache - server config is *your* responsibility. – ceejayoz Oct 12 '17 at 14:23
  • Thanks for the comment. Just want to make sure there is no other recommended way to handle this in VueJS. – Ivan Lim Oct 12 '17 at 14:30
  • It's always better to tackle this server-side. JS can do it, but by the time JS executes sensitive data may *already* have been sent to the browser. – ceejayoz Oct 12 '17 at 14:32
  • I guess 1 reason for JS-based redirect is if your site is behind proxy and it covers the https for you, such as cloudflare e.g. and in your server, that you dont have an option, to open your port 443 to serve https traffic. and at some case, in this scenario, it could lead to an internal redirect loop. e.g. http-https-http and so on... – bubjavier Mar 10 '20 at 16:13
  • in case you don't have control over the server you might still want to enforce SSL via Javascript. Here is how: https://stackoverflow.com/questions/4723213/detect-http-or-https-then-force-https-in-javascript – henon May 14 '20 at 10:47

0 Answers0