Redirecting www to non-www urls

7 posts / 0 new
Last post
#1 Mon, 08/06/2012 - 13:06
blackbricksoftware

Redirecting www to non-www urls

I was curious if there was a setting in Virtualmin where I could set all domains to default to using a non-www url and redirect the www url to the non-www url.

I know this can easily be done with Apache's mod_rewrite individually for each domain, but I was hoping for a more general solution that would not require setting each domain individually.

Wed, 08/15/2012 - 02:08
blackbricksoftware

Sorry for bumping my own post.

I have gone through and just tacked in a rewrite into all my domain in Virtualmin, but I am still hoping for a more global way of doing this. It seems like it would be a more common question considering Virtualmin's seemingly loose handling of www and non-www requests.

Wed, 08/15/2012 - 05:42
premierhw

Personally I use my DNS registrar (Namecheap) to do this at the DNS level.

@           redirect to            http://www.name.com
www         a record               1.2.3.4

Of course you would need to set www as the redirect in your case.

Wed, 08/15/2012 - 06:19
Locutus

@evad: Can you give an example of what exactly (hostname, IP, port, URL?) you'd like to have redirected where?

Redirecting a URL, as in web URL, requires a webserver to handle the request, which naturally means you need to configure the webserver to do that. Depending on what exactly you wish to redirect, you can probably make a global configuration entry in Apache to have it redirect requests to all hostnames accordingly.

Wed, 08/15/2012 - 10:50
blackbricksoftware

premierhw:

I had not thought of using my DNS. I currently have both the www and @ records pointed to my IP address.

Locutus:

Virtualmin handles www.domain.com and domain.com requests in the same way by default. They both get directed to the public_html folder of the correct account.

I am looking to have www.domain.com always redirect to domain.com when it is handled. Right now I just have a mod_rewrite setting setup in a .htaccess file in each domain to make sure the www.domain.com requests are always redirected to domain.com.

I tried creating a subserver for the www subdomain, but virtualmin told me it was already handling www requests and that creating the subserver was not necessary.

Thu, 08/16/2012 - 02:17
Locutus

DNS does not offer "redirection" for browser URLs in that regard. What the registrar mentioned above does is either a simple CNAME, or they have a webserver running which does the redirection. URLs are handled by web servers, not DNS.

If you wish to do the redirection yourself, both the www and non-www variant MUST point to your IP. Except you're going to use a webserver-based redirection service at your registrar.

Evad, may I ask why you wish to redirect ALL www.example.com requests to example.com? I'm not sure if that is doable on a global basis in Apache. You might be best off adding the appropriate mod_rewrite directives to your server template, to have them auto-applied individually to each new domain.

Thu, 08/16/2012 - 11:48
blackbricksoftware

This causes me some problems with single domain ssl certificates. It also messes up social share button counts. If someone likes the www homepage and someone else likes the non www home page, they are not treated as the same url, so each page gets a like count of one, instead of the homepage having a like count of 2.

Thank you for your help!

Topic locked