当我使用http而不是https时,Apache会重定向到我站点的另一个页面
我在我的网站上安装了一个ssl证书,当我输入一个带有“https”的url时,它会按应该的方式加载,但是当我输入一个只有“http”的url时,它会将我重定向到“”,我不知道为什么。这就是我的htaccess所包含的内容当我使用http而不是https时,Apache会重定向到我站点的另一个页面,apache,.htaccess,Apache,.htaccess,我在我的网站上安装了一个ssl证书,当我输入一个带有“https”的url时,它会按应该的方式加载,但是当我输入一个只有“http”的url时,它会将我重定向到“”,我不知道为什么。这就是我的htaccess所包含的内容 Options +FollowSymLinks -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^imgs$ imgs [NC,L,QSA]
RewriteRule ^static$ static [NC,L,QSA]
RewriteRule ^test$ index.html [NC,L,QSA]
RewriteRule ^login$ index.html [NC,L,QSA]
RewriteRule ^menu$ index.html [NC,L,QSA]
RewriteCond %{HTTPS} on!
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
所有规则都说index.html,因为它是SPA,在我安装de-ssl并添加最新的两行代码之前,它没有问题,但现在我使用http输入的每个url都重定向到“”问题是,重定向是在您重写url之后发生的。您的重定向需要在重写之前完成。另外,前两个条件仅应用于第一个规则,而不是全局应用。你可能想要一些类似的东西:
Options +FollowSymLinks -MultiViews
RewriteEngine On
# Redirect first, then apply any rewrites after the browser loads the new URL
RewriteCond %{HTTPS} on!
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# If any request is for an existing resource, stop the rewriting immediately
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^imgs$ imgs [NC,L,QSA]
RewriteRule ^static$ static [NC,L,QSA]
RewriteRule ^test$ index.html [NC,L,QSA]
RewriteRule ^login$ index.html [NC,L,QSA]
RewriteRule ^menu$ index.html [NC,L,QSA]
谢谢,兄弟。它可以工作,但我不得不删除“RewriteRule^-[L]”这一行,因为我的所有URL都找不到,谢谢。