Angular 5、apache和https
我有一个Angular 5应用程序,我需要将所有流量重定向到Https,但情况并非如此。我只有访问权限。htaccess可以这样做 起初,我有这样的配置:Angular 5、apache和https,angular,apache,.htaccess,https,Angular,Apache,.htaccess,Https,我有一个Angular 5应用程序,我需要将所有流量重定向到Https,但情况并非如此。我只有访问权限。htaccess可以这样做 起初,我有这样的配置: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
但是我有太多的重定向,无法加载页面
然后,我尝试将我的conf替换为:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . https://%{SERVER_NAME}/index.html [L]
</IfModule>
重新启动发动机
重写基/
重写规则^index\.html$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则。https://%{SERVER_NAME}/index.html[L]
所有的URI都会被处理,但它们总是以角度重定向到“/”,所以我不能使用Url导航(例如,我有一个/admin部分,只能通过Url访问)
我不习惯apache,我通常使用nginx,有人知道如何解决我的问题吗
谢谢如果有人有同样的问题,我设法解决了。htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{ENV:HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R,L]
RewriteBase /dist
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
重新启动发动机
重写cond%{ENV:HTTPS}!在…上
重写规则(.*)https://%{HTTP_HOST}/$1[R,L]
重写基/区
重写规则^index\.html$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.html[L]
我猜我第一次尝试的错误是https测试的条件谢谢mel mouk。在我的例子中,我的
dist
文件直接在public\u html
中,所以我不需要重写base,我尝试了没有它的解决方案,但没有成功,最后我想我知道了失败的原因(通过反复试验/试验),而且在每一行之间,我的服务器显然需要一条空行,比如:
<IfModule mod_rewrite.c>
RewriteEngine On
重新启动发动机
而不是:
<IfModule mod_rewrite.c>
RewriteEngine On
重新启动发动机
这太奇怪了,但我明白为什么会这样。不管怎样,我想我会让其他任何人知道,如果绝对没有什么是为你工作
<IfModule mod_rewrite.c>
RewriteEngine On