考慮我的主要網站是一個 Angular 應用程式https://example.com,我將dist檔案夾的內容放在public_html. 此外,還有一個 WordPress 網站https://example.com/mag/。我正在使用cpanel主機,我只能.htaccess設定重定向。
我需要將所有角度路線重定向mag/到index.html. 但是,當我使用鏈接從我的主要 Angular 應用程式轉到時https://example.com/mag/,它不會打開 WordPress 站點,而是重定向回 Angular 應用程式。
我的電流.htaccess仍然無法正常作業:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_URI} ^/mag/
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
</IfModule>
uj5u.com熱心網友回復:
我通過添加一個例外來解決這個/mag問題RewriteCond %{REQUEST_URI} !^/mag/。整體.htaccess應該是這樣的:
<IfModule mod_rewrite.c>
RewriteEngine On
# -- REDIRECTION to https (optional):
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_URI} !^/mag/ # -- <== here
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
</IfModule>
為什么這個改變能解決問題?
當您嘗試https://example.com/mag從主網站導航到時,Angular 路由以某種方式找不到/mag,因為它不是 Angular 應用程式的一部分,它會轉到Angular404頁面。所以這個例外解決了這個問題,只是因為當路由去時/mag,它不會被重定向到index.html(Angular)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/459213.html
