AngularJS SSL .htaccess问题 [英] AngularJS SSL .htaccess woes

查看:55
本文介绍了AngularJS SSL .htaccess问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在已经为html5Mode直接链接设置的.htaccess文件中启用SSL,但始终会导致重定向循环.我在stackoverflow上找到的最接近的问题是但即使从这里我也无法弄清楚(我是htaccess文件的新手.)

I'm trying to enable the use of SSL on my .htaccess file that has already been set up for html5Mode direct linking but it's always resulting in a redirect loop. The closest question I've found on stackoverflow is this but even from here I can't figure it out (I'm new to htaccess files).

AngularJS html5Mode直接链接htaccess文件是

AngularJS html5Mode direct linking htaccess file is

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.html [L]

,这很完美.说明强制SSL htaccess为

Forcing SSL htaccess is

RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

也可以单独使用,但是当尝试将它们组合在一起(在通过index.html进行路由之前强制使用SSL)时,会导致重定向循环.如果我不得不猜测,那是因为它首先重定向到使用https,然后第二次重定向再次使用http通过index.html进行路由.但是,我不知道如何测试或修复它.

and this also works by itself but when trying to combine them (forcing SSL before routing through index.html) it results in a redirect loop. If I had to guess it would be because it first redirects to using https and then the second redirect routes through index.html using http again. However, I don't know how to test it or fix it.

任何帮助将不胜感激.

如前所述,我应该包括尝试导致循环的内容.

As pointed out I should've included what I tried resulting in a loop.

RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.html [L]

推荐答案

我不是生成htaccess文件的专家,但是我找到了一种解决方案,该解决方案正在我的服务器上运行.

I am not an expert in generating htaccess files, but I found a solution, which is working on my server.

尝试一下:

RewriteEngine on

RewriteBase /

RewriteCond %{SERVER_PORT} 80
RewriteRule ^ https://%{SERVER_NAME}/index.html [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ https://%{SERVER_NAME}/index.html [L]

它正在强制使用https,并且Angular的HTML5模式也运行良好.不要忘记在Web服务器配置文件中同时设置http(端口80)和https(端口443)URL.当然,这个角度代码片段仍然非常重要:

It's forcing https and Angular's HTML5 mode is working well too. Don't forget to set up both http (port 80) and https (port 443) urls in your web server config file. Of course this angular code snippet is still really important:

$locationProvider.html5Mode(true);

祝你好运,希望我能对你有所帮助!

Good luck, I hope I helped you!

这篇关于AngularJS SSL .htaccess问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆