[英]Redirect from http to https using Angular and Apache not working
我已經安裝了SSL證書,並且希望將所有流量從http重定向到https。 我已將此部分添加到我的Apache服務器中:
IncludeOptional conf.d/*.conf
<VirtualHost *:80>
ServerName www.memoriesgameseries.com
Redirect "/" "https://www.memoriesgameseries.com/"
</VirtualHost>
Listen 443
<VirtualHost *:443>
ServerName www.memoriesgameseries.com
SSLEngine on
SSLCertificateFile "/etc/httpd/memoriesgameseries_com.crt"
SSLCACertificateFile "/etc/httpd/memoriesgameseries_com.ca-bundle"
SSLCertificateKeyFile "/etc/httpd/memoriesgameseries.com.key"
</VirtualHost>
根據Apache文檔。 我的Angular路由文件如下所示:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { MemoriesComponent } from '../memories/memories.component';
import { TearsComponent } from '../tears/tears.component';
const routes: Routes = [
{ path: '', redirectTo: 'memories', pathMatch: 'full' },
{ path: 'memories', component: MemoriesComponent },
{ path: 'tears', component: TearsComponent }
]
@NgModule({
imports: [ RouterModule.forRoot(routes)],
exports: [ RouterModule ]
})
export class RoutingModule {};
但是,無論何時我嘗試通過http訪問網站,而不是正確重定向,當我鍵入根地址(例如www.memoriesgameseries.com
和http://memoriesgameseries
,重定向都根本無法啟動。 當我在根域上方輸入URL時,例如http://memoriesgameseries.com/memories
,重定向就會啟動,並且我在瀏覽器中看到https URL(例如https://www.memoriesgameseries.com/memories
),但我得到:
未找到
在此服務器上找不到請求的URL /內存。
服務器的響應。 是什么可能導致此問題?
關鍵是服務器正在嘗試管理404。這是沒有生命的,讓SPA為您完成。
404重定向到index.html時
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.