我正在使用 apache mod rewrie 将 http 重定向到 https,但现在无法连接到 localhost/phpmyadmin

我正在使用 apache mod rewrie 将 http 重定向到 https,但现在无法连接到 localhost/phpmyadmin

这是我的 /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] 

相关内容