![我正在使用 apache mod rewrie 将 http 重定向到 https,但现在无法连接到 localhost/phpmyadmin](https://linux22.com/image/600910/%E6%88%91%E6%AD%A3%E5%9C%A8%E4%BD%BF%E7%94%A8%20apache%20mod%20rewrie%20%E5%B0%86%20http%20%E9%87%8D%E5%AE%9A%E5%90%91%E5%88%B0%20https%EF%BC%8C%E4%BD%86%E7%8E%B0%E5%9C%A8%E6%97%A0%E6%B3%95%E8%BF%9E%E6%8E%A5%E5%88%B0%20localhost%2Fphpmyadmin.png)
这是我的 /etc/apache2/sites-enabled/000-default
<VirtualHost *:80>
ServerAdmin [email protected]
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://mysite.com
DocumentRoot /var/www/http
<Directory />
Options None
AllowOverride None
</Directory>
<Directory /var/www/http>
Options -Indexes -FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
不确定如何修复此问题。有什么想法吗?
答案1
您应该能够连接到'https://localhost/phpmyadmin“”。
或者,您可以修改 RewriteRule 以包含匹配字符串的反向引用。
RewriteRule /(.*) https://mysite.com/$1 [R=301]
答案2
我将使用以下 RewriteRules 来完成重定向。这将保留请求的 URL,并将协议更改为 https://
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://%{SERVER_NAME}%{REQUEST_URI} [R]