使用Angular的默认.htaccess文件强制https://

时间:2018-06-26 08:24:47

标签: angular .htaccess

Angular提供了默认的.htaccess文件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

但是,这并不强制https://

无论我如何尝试(使用有关https://强制的类似问题的答案或摘要),它总是会中断路由,并导致404Apache is functioning normally通知。


如何在保持路由不变的情况下更新此代码段以强制https://?

1 个答案:

答案 0 :(得分:2)

尝试一下

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
相关问题