Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用XAMPP将HTTP重定向到HTTPS_Php_Apache_.htaccess_Mod Rewrite_Xampp - Fatal编程技术网

Php 如何使用XAMPP将HTTP重定向到HTTPS

Php 如何使用XAMPP将HTTP重定向到HTTPS,php,apache,.htaccess,mod-rewrite,xampp,Php,Apache,.htaccess,Mod Rewrite,Xampp,我正在尝试使用XAMPP将HTTP重定向到HTTPS。 我已经在多个网站上看到了推荐此网站的所有问题和多个答案: 这就是我所做的: 我取消了行的注释: LoadModule rewrite_module modules/mod_rewrite.so 在C:/xampp/apache/config/httpd.conf中,删除前面的# 然后我在C:/xampp/apache/config/extra/httpd xampp.conf中输入了这个: <IfModule mod_rewrit

我正在尝试使用XAMPP将HTTP重定向到HTTPS。
我已经在多个网站上看到了推荐此网站的所有问题和多个答案:

这就是我所做的:
我取消了行的注释:

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
重写cond%{HTTPS}=在…上
重写cond%{REQUEST_URI}xampp
重写规则^(.*)https://%{SERVER_NAME}$1[R,L]
#将/phpMyAdmin文件夹重定向到https
重写cond%{HTTPS}=在…上
重写cond%{REQUEST_URI}phpmyadmin
重写规则^(.*)https://%{SERVER_NAME}$1[R,L]
#重定向/安全文件夹到https
重写cond%{HTTPS}=在…上
重写cond%{REQUEST_URI}安全性
重写规则^(.*)https://%{SERVER_NAME}$1[R,L]
#将/webalizer文件夹重定向到https
重写cond%{HTTPS}=在…上
重写cond%{REQUEST_URI}webalizer
重写规则^(.*)https://%{SERVER_NAME}$1[R,L]

我进行了三次检查,确认所有操作都正确无误,保存了所有内容,并重新启动了XAMPP,但仍然无法重定向到HTTPS。请帮忙

我自己找到了答案;我有vhosts设置,我必须

<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
重写cond%{HTTPS}=在…上
重写cond%{REQUEST_URI}xampp
重写规则^(.*)https://%{SERVER_NAME}$1[R,L]
#将/phpMyAdmin文件夹重定向到https
重写cond%{HTTPS}=在…上
重写cond%{REQUEST_URI}phpmyadmin
重写规则^(.*)https://%{SERVER_NAME}$1[R,L]
#重定向/安全文件夹到https
重写cond%{HTTPS}=在…上
重写cond%{REQUEST_URI}安全性
重写规则^(.*)https://%{SERVER_NAME}$1[R,L]
#将/webalizer文件夹重定向到https
重写cond%{HTTPS}=在…上
重写cond%{REQUEST_URI}webalizer
重写规则^(.*)https://%{SERVER_NAME}$1[R,L]
在目录中,我希望在C:/xampp/apache/config/extra/httpd-vhosts.conf中重定向

robs笔记本的最后几行解释了这一点:

此重定向需要记住的一点是,如果您有虚拟主机,则需要将重定向代码(使用RewriteCond和RewriteRule)放在虚拟主机声明中,否则重定向将不起作用。

如果(!isset($\u SERVER['HTTPS'))
,则只需使用
头即可(“地点:https://...“);退出()
user2078421这正是我所尝试的,但对我来说不起作用。你应该准确地描述你试图实现的重定向。你的示例代码所做的不仅仅是将HTTP重定向到HTTPS.w3dk。它还做了什么?然后你的4条规则可以作为一条规则大大简化。然而,你现有的指令redirec不仅仅是“
/xampp
文件夹”等,如果您使用的是虚拟主机,那么您应该能够避免检查HTTPS。(?)