我正在尝试使用 XAMPP 将 HTTP 重定向到 HTTPS。
我已经在推荐该网站的多个网站上看到了所有问题和多个答案: XAMPP: SSL Encrypt the Transmission of Passwords with HTTPS | Rob's Notebook
这就是我所做的:
我取消了该行的注释:
LoadModule rewrite_module modules/mod_rewrite.so
在C:/xampp/apache/config/httpd.conf
中删除前面的#
。
然后我在 C:/xampp/apache/config/extra/httpd-xampp.conf
中输入了以下内容:
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect /xampp folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} xampp
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
# Redirect /phpMyAdmin folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} phpmyadmin
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
# Redirect /security folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} security
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
# Redirect /webalizer folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} webalizer
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
</IfModule>
我三次检查了所有操作是否正确,保存了所有内容,然后重新启动了 XAMPP,但仍然无法重定向到 HTTPS。请帮忙!
最佳答案
我自己找到了答案;我有虚拟主机设置,我必须放置
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect /xampp folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} xampp
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
# Redirect /phpMyAdmin folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} phpmyadmin
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
# Redirect /security folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} security
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
# Redirect /webalizer folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} webalizer
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
</IfModule>
在我想要重定向的目录内 C:/xampp/apache/config/extra/httpd-vhosts.conf。
这在 robs 笔记本的最后几行中进行了解释:
此重定向需要记住的一件事是,如果您有虚拟主机,则需要将重定向代码(使用 RewriteCond 和 RewriteRule)放置在虚拟主机声明中,否则重定向将不起作用。/em>
关于php - 如何使用 XAMPP 将 HTTP 重定向到 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42209233/