Automatically redirect requests for root domain to www subdomain on all new sites
I'd like to have all new domains include a rule, either in a VirtualHost or a .htaccess, that redirects requests to the root domain (example.com) to a subdomain (www.example.com). Currently, I'm doing this manually by putting a .htaccess file in everyone's home folders like this:
This is starting to get tedious to do for every account, since (in my case) almost all clients want the functionality. Is there a way to configure WHM do do something like this for every new domain when it's created? I don't much care how it's achieved, but it's important that I still be able to disable it on a per-site basis if requested.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]This is starting to get tedious to do for every account, since (in my case) almost all clients want the functionality. Is there a way to configure WHM do do something like this for every new domain when it's created? I don't much care how it's achieved, but it's important that I still be able to disable it on a per-site basis if requested.
-
Hello :) The following document explains how to automatically add custom entries to all VirtualHosts on the server: Changes Contained Within a VirtualHost Directive Thank you. 0 -
Thanks, that looks useful. The changes I need to make will have to reference the name of the domain within themselves. Is there some variable I can use that would represent the current domain? Alternatively, is there a different way to do that redirection that would be domain-agnostic? 0 -
You can review the template files for the version of Apache installed on your system via: /var/cpanel/templates This should give you a better idea on how to reference a domain name, and is likely the better route compared to attempting to formulate a non-domain specific Mod_Rewrite rule. Thank you. 0
Please sign in to leave a comment.
Comments
3 comments