• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

204
Views
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

about 3 years ago · Santiago Trujillo
1 answers
Answer question

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.

about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error