[英]How to redirect HTTP to HTTPS using XAMPP
我正在嘗試使用 XAMPP 將 HTTP 重定向到 HTTPS。
我已經在推薦這個網站的多個網站上看到了所有問題和多個答案: XAMPP: SSL Encrypt the Transmission of Passwords with 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。 請幫忙!
我自己找到了答案; 我有虛擬主機設置,我必須放置
<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 。
這在 rob notebook 的最后幾行中解釋了:
使用此重定向要記住的一件事是,如果您有虛擬主機,則需要將重定向代碼(使用 RewriteCond 和 RewriteRule)放在虛擬主機聲明中,否則重定向將不起作用。
第 1 步:在xampp\apache\conf\extra\httpd-ssl.conf
中為域配置 SSL
<VirtualHost 127.0.0.1:443>
DocumentRoot "/your/project/path"
ServerName yourdomain.com
SSLEngine on
SSLCertificateFile "/your/ssl/server.crt"
SSLCertificateKeyFile "/your/ssl/server.key"
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "C:/xampp/apache/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
第 2 步:現在配置在xampp\apache\conf\extra\httpd-vhosts.conf
http 重定向到 https
<VirtualHost *:80>
RewriteEngine on
ServerName yourdomain.com
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
</VirtualHost>
第 3 步:重新啟動 Xampp
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.