CPANEL-40585 - Force HTTPS on password-protected directory
We have a password-protected directory
that is not automatically redirecting to a secure/HTTPS page. The
has a redirect rule for the entire website, but it is not working for this directory because of the password-protection. Does anyone have suggestions? pre_virtual_host.conf (Apache Configuration " Include Editor)
public_html/.htaccess
/adminthat is not automatically redirecting to a secure/HTTPS page. The
.htaccesshas a redirect rule for the entire website, but it is not working for this directory because of the password-protection. Does anyone have suggestions? pre_virtual_host.conf (Apache Configuration " Include Editor)
AuthType Basic
AuthName "Authentication Required"
AuthUserFile /etc/apache2/htpasswd/.htpasswd
Require valid-user
ErrorDocument 401 "Authentication Required"
Options +Includes
public_html/.htaccess
#HTTPS Redirect
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
-
Hey there! I believe this is due to the order of your configuration. The Apache includes will get read before the local .htaccess with your example. However, if you use the cPanel >> Directory Privacy tool, that creates a local .htaccess inside the specific directory you're protecting with the following code: #----------------------------------------------------------------cp:ppd # Section managed by cPanel: Password Protected Directories -cp:ppd # - Do not edit this section of the htaccess file! -cp:ppd #----------------------------------------------------------------cp:ppd AuthType Basic AuthName "Protected 'public_html/privacytest'" AuthUserFile "/home/username/.htpasswds/public_html/privacytest/passwd" Require valid-user #----------------------------------------------------------------cp:ppd # End section managed by cPanel: Password Protected Directories -cp:ppd #----------------------------------------------------------------cp:ppd
Doing that instead of using the Apache include system will likely get things working how you expect.0 -
I gave that a try, but it still doesn't redirect to HTTPS when I access that directory. 0 -
Based on Apache 2.4, would this be the preferred 'HTTPS redirect' method? NameVirtualHost *:80 ServerName www.yourdomain.com Redirect / https://www.yourdomain.com0 -
I always perform the redirect inside the .htaccess file. For other pieces of software, such as WordPress, you may need a plugin like ReallySimpleSSL or similar to ensure the WordPress structure is redirected properly. That is the correct format for an Apache redirect, although many people prefer to use " Redirect permanent / Example Domain" as the last line. With a cPanel-based machine though, remember you can't edit the Apache configuration directly. 0
Please sign in to leave a comment.
Comments
6 comments