【发布时间】:2017-07-01 17:51:36
【问题描述】:
我正在尝试使用 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。请帮忙!
【问题讨论】:
-
if( !isset( $_SERVER['HTTPS'] ) )那么你可以简单地使用你的header('Location: https://...'); exit(); -
user2078421 这正是我尝试过的,但它对我不起作用。
-
您应该准确描述您想要实现的重定向。您的示例代码不仅仅是将 HTTP 重定向到 HTTPS。
-
w3dk 那它还在做什么
标签: php apache .htaccess mod-rewrite xampp