Reputation: 7157
Angular provides a default .htaccess
file in its documentation:
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
However, this does not force https://
.
Whatever I try (using answers or snippets from similar questions about https:// forcing), it always breaks the routing, and results in either 404
or the Apache is functioning normally
notice.
How do I update this snippet to force https://, while keeping the routing intact?
Upvotes: 1
Views: 1423
Reputation: 15070
Try this
RewriteEngine On
# Force https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
Upvotes: 8