在虚拟主机中使用.htaccess身份验证从http自动重定向到https

时间:2013-05-16 05:24:22

标签: apache .htaccess redirect ssl web-hosting

您好我已经在apache上配置了虚拟主机,并使用SSL进行.htaccess身份验证。我输入网址https://www.example.com:9004/test.php时工作正常,但当我输入http://www.example.com:9004/test.php时,我收到此错误。

Bad Request

Your browser sent a request that this server could not understand.
Reason: You're speaking plain HTTP to an SSL-enabled server port.
Instead use the HTTPS scheme to access this URL, please.
Hint: https://www.example.com/  

我的 httpd.conf 文件看起来像这样

 Listen 9004
<VirtualHost *:9004>
    ServerAdmin root@localhost
    DocumentRoot /mnt/work/httpd
    <Directory "/mnt/work/httpd">
    Options FollowSymLinks
     AllowOverride AuthConfig
    </Directory>
  SSLEngine On
  SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
  SSLCertificateKeyFile /mnt/work/httpd/www.example.com.key
  SSLCertificateFile /mnt/work/httpd/www.example.com.crt
#RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.example.com:9006%{REQUEST_URI}
    ServerName www.example.com
    ErrorLog "/mnt/work/log/error_log"
    CustomLog "/mnt/work/log/access_log" combined
</VirtualHost>

我的SSL /etc/httpd/conf.d/ssl.conf 文件是

LoadModule ssl_module modules/mod_ssl.so

#
# When we also provide SSL we have to listen to the
# the HTTPS port in addition.
#
Listen 9006

和我的 .htaccess 文件是

AuthType Digest
AuthName "Protected"
AuthDigestProvider file
AuthGroupFile /dev/null
AuthUserFile /mnt/work/httpd/digest_auth
Require user johan

我该怎么办才能点击http:/www.example.com:9004/test.php时自动重定向到https://www.example.com:9004/test.php

请帮帮我......

0 个答案:

没有答案