我遇到一个问题,当网站位于https时,我网站中的所有链接都被破坏了。无论如何,我需要做的是将所有请求从http
重定向到https
,因此我在.htaccess
添加了以下代码。
# Redirect from http to https.
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^project-local\.com*
RewriteRule ^(.*)$ https://project-local.com/$1 [L,R=301]
重定向工作正常但如果我点击网站中的任何链接,当它在https中时,会发生什么情况所有响应都是404.
这是我的ssl vhost看起来像:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName project-local.com
DocumentRoot /home/snake/repo/project-a/docroot
ErrorLog ${APACHE_LOG_DIR}/project-a-ssl_error.log
CustomLog ${APACHE_LOG_DIR}/project-a-ssl_access.log common
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
<Directory /home/snake/repo/project-a/docroot/>
Require all granted
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
</IfModule>
答案 0 :(得分:1)
您的http->https
规则不正确,可能导致无限重定向,您可以使用:
RewriteCond %{HTTP_HOST} ^project-local\.com$ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301,NE]