Paths

Learn about base and relative paths.

We'll cover the following

Base path

Make sure that users are on the HTTPS version of your site whenever needed. This is done in Apache/Nginx configs using redirects. Alternatively, set the base path of your application to use your HTTPS URL: https://yourApp.com. Then, force a redirect using the base path if a user enters on HTTP.

Sometimes you want to allow HTTP on certain pages and require HTTPS on others. This is where your web server configs and proper code routing come in.

Relative paths

Here’s one more tip to make your life easier when using HTTP and HTTPS on one site. URLs for assets, like CSS or JS, can begin with double forward slashes instead of http:// or https:// to reference the current protocol. For example, on your home page, you might have:

<link type="text/css" rel="stylesheet" href="//assets/main.css" />

Navigating to https://yourApp.com loads:

https://yourApp.com/assets/main.css

Whereas navigating to http://yourApp.com would load:

http://yourApp.com/assets/main.css

That’s just a little trick to make your life a little easier.

Get hands-on with 1400+ tech skills courses.