Modrewrite phpmyadmin 到 HTTPS

Modrewrite phpmyadmin 到 HTTPS

我正在使用它来强制通过 HTTPS 访问 phpmyadmin,但它仍然停留在 HTTP 上,而网站 .htaccess 文件中的其他指令工作正常。

RewriteEngine On

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^/phpmyadmin/(.*)$ https://my.site.net/phpmyadmin/$1 [R,L]


<VirtualHost 89.24.24.24:80> 
DocumentRoot /home/site/public_html 
ServerName my.mysite.net 
ErrorLog /var/log/httpd/error_log 
ErrorLog /var/log/httpd/error_log 
CustomLog "|/usr/sbin/rotatelogs home/sitel/logs/access_log.%Y.%m.%d 86400" combined 
Options ExecCGI 
TraceEnable off 
RewriteEngine on 
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK) RewriteRule .* - [F] 
</VirtualHost>


<VirtualHost 89.24.24.24:443>

DocumentRoot /home/site/public_html/phpmyadmin
ServerName my.mysite.net

SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/csvsvsv3.crt
SSLCertificateKeyFile /etc/pki/tls/private/site.key
SSLCertificateChainFile /etc/pki/tls/certs/bundle.crt

SSLProtocol -ALL +SSLv3 +TLSv1
SSLCipherSuite RC4:HIGH:!ADH:!DH:!AES:!EXPORT:!SSLv2:!3DES

Options ExecCGI

TraceEnable off

RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</VirtualHost>



[rid#7f0269d20118/initial] (2) init rewrite engine with requested uri /phpmyadmin/
[rid#7f0269d20118/initial] (3) applying pattern '.*' to uri '/phpmyadmin/'
[rid#7f0269d20118/initial] (4) RewriteCond: input='GET' pattern='^(TRACE|TRACK)' => not-matched
[rid#7f0269d20118/initial] (1) pass through /phpmyadmin/
[rid#7f0269d26148/subreq] (2) init rewrite engine with requested uri /phpmyadmin/index.php
[rid#7f0269d26148/subreq] (3) applying pattern '.*' to uri '/phpmyadmin/index.php'
[rid#7f0269d26148/subreq] (4) RewriteCond: input='GET' pattern='^(TRACE|TRACK)' => not-matched
[rid#7f0269d26148/subreq] (1) pass through /phpmyadmin/index.php
[rid#7f0269d20118/initial] (2) init rewrite engine with requested uri /phpmyadmin/phpmyadmin.css.php
[rid#7f0269d20118/initial] (3) applying pattern '.*' to uri '/phpmyadmin/phpmyadmin.css.php'
[rid#7f0269d20118/initial] (4) RewriteCond: input='GET' pattern='^(TRACE|TRACK)' => not-matched
[rid#7f0269d20118/initial] (1) pass through /phpmyadmin/phpmyadmin.css.php
[rid#7f0269d20118/initial] (2) init rewrite engine with requested uri /phpmyadmin/themes/original/img/logo_right.png
[rid#7f0269d20118/initial] (3) applying pattern '.*' to uri '/phpmyadmin/themes/original/img/logo_right.png'
[rid#7f0269d20118/initial] (4) RewriteCond: input='GET' pattern='^(TRACE|TRACK)' => not-matched
[rid#7f0269d20118/initial] (1) pass through /phpmyadmin/themes/original/img/logo_right.png
[rid#7f0269d20118/initial] (2) init rewrite engine with requested uri /phpmyadmin/print.css
[rid#7f0269d20118/initial] (3) applying pattern '.*' to uri '/phpmyadmin/print.css'
[rid#7f0269d20118/initial] (4) RewriteCond: input='GET' pattern='^(TRACE|TRACK)' => not-matched
[rid#7f0269d20118/initial] (1) pass through /phpmyadmin/print.css

答案1

这可能是你把事情搞得太复杂了。我从来没有用过 mod-rewrite 来做这件事;设置$cfg\['ForceSSL'\] = true;通常这就是我需要做的全部(当然前提是我的 Apache 服务器在 https 端设置正确)。

答案2

尝试用以下方式替换你的条件

RewriteCond %{HTTPS} !=on

答案3

这对我以前有用:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

由于您似乎在共享主机上,无法访问主 apache 配置文件来启用 RewriteLog,因此您可以查看此帖子以获取有关如何调试重写规则的一些想法: https://stackoverflow.com/questions/9153262/tips-for-debugging-htaccess-rewrite-rules

答案4

我记得几年前我这样做的时候,需要配置 SSL 才能使用 HTTPS。我一直在寻找我的笔记,但没有找到

尝试一下本指南。它适用于 Linux,因此如果你使用其他系统,至少它会为你指明正确的方向

http://www.howtoforge.com/how-to-set-up-an-ssl-vhost-under-apache2-on-ubuntu-9.10-debian-lenny

相关内容