Mobile app version of vmapp.org
Login or Join
Harper822

: Automatic redirection from http to https with .htaccess authentication in virtual hosting Hi I have configured Virtual host on apache with .htaccess authentication with SSL. It's working fine when

@Harper822

Posted in: #Apache2 #Htaccess #Https #Redirects #Virtualhost

Hi I have configured Virtual host on apache with .htaccess authentication with SSL. It's working fine when I typed url www.example.com:9004/test.php but when I typed www.example.com:9004/test.php I am getting this error:

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: www.example.com/


My httpd.conf file look like this:

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 (.*) www.example.com:9006%{REQUEST_URI} ServerName example.com ErrorLog "/mnt/work/log/error_log"
CustomLog "/mnt/work/log/access_log" combined
</VirtualHost>


And my /etc/httpd/conf.d/ssl.conf file is:

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


And Mmy .htaccess file is:

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


What should I do so that when I hit http:/www.example.com:9004/test.php it will automatically redirect to www.example.com:9004/test.php.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Harper822

2 Comments

Sorted by latest first Latest Oldest Best

 

@Moriarity557

It seems you want 9004 for https; 9006 for http; You should redirect http connection on 9004 port to https connection on same 9004 port.

However your config redirects example.com:9004 to example.com:9006 which does not make much sense since 9006 port is for http. Just replace 9006 by 9004 in your RewriteRule.

Some additional info on url redirection: wiki.apache.org/httpd/RedirectSSL

10% popularity Vote Up Vote Down


 

@Murray432

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


Should do the trick.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme