Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

209
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda