• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

215
Vistas
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 3 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

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 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda