apacheno-www

Own example.org and can't get www.example.org to redirect


I own http://0x3c.org/ and everything is working as it should. I am using Google Domains and have Dynamic DNS set up with them to point to the Apache server inside of my house.

My issue is that http://www.0x3c.org/ does not redirect to http://0x3c.org/, instead it says that http://www.0x3c.org/ does not exist. Additionally, I do not want http://www.0x3c.org/ to exist.

I would like for it to redirect, and don't know how to go about setting it up. Can anyone guide me as to how to do this?

Thank you.


Solution

  • www.0x3c.org has to exist, in order to redirect the requests. You have to create a DNS (CNAME) entry for www.0x3c.org, direct it (preferably) to the same server that serves 0x3c.org and then use Apache rewrite rules, as described here:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]