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

标签 php apache .htaccess mod-rewrite xampp

我正在尝试使用 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/

相关文章:

php - set_time_limit() 和 ini_set ('max_execution_time' 之间的区别,...)

php - 如何自动刷新有错误的 HTML 页面?

php - 我怎样才能在第一次出现时停止? - 拉拉维尔

html - 网站运行速度非常慢

linux - Apache 中的 .htaccess 不工作

node.js - 将 .htacees 指向使用 SSL 配置的 Node 服务器

apache - .htaccess 将子域重写到目录

php - WooCommerce 订阅 - 获取特定订阅的相关订单 ID

python - 如何仅使用 .pyo 文件(没有 .py)来使用 mod_wsgi?

apache - 如何获取 Shell 脚本来更改文件权限?