0

I'm not sure where I'm going wrong, but I cannot seem to access my website without including the www prefix in the URL, otherwise I can access it fine. I have the following DNS records:

A: @ - directs to 000.000.000.000

CNAME: *.example.com - is an alias of example.com

And in my .conf file, I have the following:

<VirtualHost *:80>
        ServerName example.com

        Redirect permanent / http://www.example.com/
</VirtualHost>

<VirtualHost *:80>
        ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/example.com/public

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

The file should be working because I can access the site at www.example.com, so I'm not sure if there's a mistake in my Redirect or if it's something else, but I'm struggling to figure this out.

3
  • 2
    What is the domain name? Aug 31 '18 at 0:21
  • 1
    A wildcard CNAME to a zone apex is almost certainly not a good idea.
    – womble
    Aug 31 '18 at 0:33
  • Please stop useless (and bad) obfuscation. Aug 31 '18 at 2:13
1

You have a CNAME record for "*.example.com" which only accounts for having a . in front of the domain with anything (including "www") preceding it, so it would work if you tried something like test.example.com as . Make a new A record with @ in the field where you would put "www".

15
  • Why would I need to do that if I already have the A record? Aug 31 '18 at 0:20
  • @user4181107 You need 2 A records: 1 with "www" and 1 with "@", both pointing to the same IP. You can keep your wildcard CNAME as is to catch everything else. You can read more about it here.
    – Jesse P.
    Aug 31 '18 at 0:21
  • 1
    There is no indication in the question that there is a specific record for www.
    – womble
    Aug 31 '18 at 0:34
  • 2
    Presumably the wildcard CNAME is doing its job. But without the actual domain name to poke against, we're all just guessing as to what's really going on.
    – womble
    Aug 31 '18 at 0:37
  • 1
    @user4181107 If that doesn't work, you'll need to tell us your actual domain name so we can look at the records ourselves.
    – Jesse P.
    Aug 31 '18 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.