Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

208
Vistas
Is there a uniform https redirect method that should work for both cPanel and VestaCP when apache htpasswd is enabled?

I operate websites that run under both VestaCP and cPanel. While developing the sites I set up htpassword protection, the password syntax like this:

AuthType Basic
AuthUserFile /home/the-account/htpasswd
AuthName "Restricted"
Require valid-user

For redirection to get everything to redirect to https://www.the-website... I use:

RewriteEngine on
RewriteBase /

Options +FollowSymlinks

# Redirect http to https

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.website.ext$1 [R,L]

The redirect lines work perfectly if password protection is not enabled. All of:

website.ext
www.website.ext
http://website.ext

redirect to:

https://www.website.ext (the goal)

However the behavior is different in VestaCP vs cPanel and breaks severly in cPanel. In vesta when you visit the url like website.ext it displays the apache login screen and first you have to sign in as http:// then a second time as https://www. but it works and you end up at the goal.

With cPanel it breaks. If you attempt to sign in as any of those unfully qualified URLs you end up at a timeout, not found page, something like:

www.website.ext401.shtml.

The ext and 401.html are run together as you see above. The primary page error is: The site can't be reached. If you attempt to sign in as https://www.website.ext it works perfectly.

Fixing the cPanel problem is important, VestaCP would be nice.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

With great help from a contractor friend here is the solution that we came up with which I have set up on multiple live and development (restricted-access) websites:

Error Document line at the first line of the file solves the "ErrorDocument 401" problem in cPanel when Apache password restriction is enabled

$website.$ext ==> your-website.com
$account ==> account folder of the home directory where the htpasswd file is stored; /home/home-folder

-------------- snip ---------------

ErrorDocument 401 default 

# Redirect http to https 

  RewriteCond %{HTTPS} off [OR]
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteRule ^(.*)$ https://www.$website.$ext/$1 [L,R=301]

# BEGIN-APACHE-RESTRICTION
<If " %{HTTPS} != 'off' && %{HTTP_HOST} == 'www.$website.$ext'">
  AuthType Basic
  AuthUserFile /home/$account/htpasswd
  AuthName "restricted area"
  Require valid-user
</If>
# END-APACHE-RESTRICTION
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda