Redirect example.com to www.example.com VPS & Apache2

Posted on

Redirect example.com to www.example.com VPS & Apache2 – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about debian, domain, vps, apache-2.2, .

I have a VPS and a domain name registered with the provider.

When I enter www.example.com my site is displayed correctly, but entering example.com does not work. I am able to ping www.example.com.

I added the following line to my apache2 default vhosts file:

ServerName example.com
ServerAlias www.example.com

But this did not work.

The VPS is a Debian5 OS.

Any ideas?
Note: There is no option via a provided control panel to add this, it’s a basic package I purchased

I know this post answers it but there are no extra comments and I’d like to know if it’s the best way:
way to redirect page to www using virtual host configuration in sites-available for apache2?

Thanks

Solution :

To get DNS resolution to work, you need to have an A record for ‘example.com’, not just ‘www.example.com’. Once that’s there, what you’ve done so far will probably work. This sounds like an DNS issue so far.

To answer the second part of your question. The answer you link to is indeed a good example of doing the redirect. The first RewriteCond may not be required if you’re not using SSL, but it should not do any harm.

Leave a Reply

Your email address will not be published. Required fields are marked *