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

312
Visualizações
Best options for Apache server to access only www version of URL

What are all of the options to access only the www version of a URL e.g. https://www.example.com. The website in question has 150 pages and we need to ensure all traffic resolves to the www version.

Example: All options for this URL https://example.com to resolve to htts://www.example.com.

I’ve used an .htaccess redirect in the past, but the question is are there any other options and which is the best option

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You have a tag of Apache, so assume you are running a reasonably recent version of Apache.

You can handle it with Apache Virtual Hosts. You will set up two files:

/etc/apache2/sites-available/www.example.com.conf

<VirtualHost *:80>

    ServerName www.example.com
    DocumentRoot /var/www/...

...

</VirtualHost>

/etc/apache2/sites-available/example.com.conf

<VirtualHost *:80>
    ServerName example.com
    Redirect permanent / https://www.example.com/

...

</VirtualHost>

In Apache you then need to enable both sites:

a2ensite www.example.com
a2ensite example.com
service apache2 reload

The first file sets up the main website: www.example.com, which directs Apache to load the DocumentRoot directory when it comes in.

The second file indicates that when example.com comes in on Port 80 - redirect to the https://www.example.com. Be sure to set the http or https depending on whether it is secure.

This kind of redirect causes the browser to change the address in the browser bar, which is the best redirect for what you are looking to do.

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