Forum Topic: Editing .htaccess for subdomains

Forum: .htaccess Forum : Redirecting • Posted by George Theodore • Updated:

I am currently using the following code in my .htaccess file to require the www in all requests. I also use a re-direct to remove the index.html to the directory.

RewriteEngine On
RewriteBase /

### re-direct IP address to www
### re-direct non-www to www
RewriteCond %{http_host} !^$ [nc]
RewriteRule ^(.*)$$1 [r=301,nc,L]

### re-direct index.html to root / ###
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*\/index\.html?\ HTTP/
RewriteRule ^(.*)index\.html?$ "/$1" [R=301,L]

My question is that I want to create a subdomain called "terms". I create the subdomain in my cPanel interface, but when I type in it changes to

I want the request to go to

I realize that www is also a subdomain so what do I need to do to keep the www that is currently working and add different subdomains like "terms", "videos", "lessons" and have them resolve to,, ?

Thanks for your help.

4 Replies to “Editing .htaccess for subdomains”

Jeff Starr
Posted by Jeff Starr

Hi George,

Normally it's possible to redirect to subdomains, but it sounds like cPanel is interfering with how subdomain URLs are configured on the server.. Before using any htaccess, I would first ask your host why that is the case and if there is a setting or code or something that will restore normal functionality.

Or, another possibility is that the www redirect is causing the issue. Such that this:

RewriteRule ^(.*)$$1 [r=301,nc,L] routing other subdomain requests as well. I'm not sure what you've heard, but the "www" prefix is not required for proper URLs. I would maybe try removing the prefix and then trying the subdomain redirects with a clean slate.

I hope something there helps, good luck!

Posted by George Theodore


Thanks for you response. I guess I did not make my question clear enough. Let me try again.

I have 5 years of SEO and backlinks to my site. I started with the and I will NOT change that. I don't want to risk losing the 500+ number one SERP positions for my keywords and my site.

I am currently running the htaccess code that I listed in the previous posting. I do know that if I don't run any htaccess file that the subdomains will resolve the way I want them to like

I want to modify the htaccess file that I have listed previously to keep the www for all requests that don't have a subdomain request, and for the requests that do have a subdomain I want them to resolve with the subdomain in the beginning of the URL. So here are the example to show what I am trying to get done.

Request → goes to
Request → okay nothing happens
Request → goes to

Thanks for your help, You are a great resource.

Jeff Starr
Posted by Jeff Starr

Have you tried placing the www code in the htaccess file located in the root of the subdomains? I don't think they will work when included in the htaccess file located in the root of the primary domain.

Edit to add that normal www-canonical htaccess should work fine if located in the correct location. Apologies if this is not the case.

I hope this helps!

Posted by Chris McCoy •

are you trying to create sub domains on the fly with htaccess without creating an actual apache entry for it? like map a sub directory on your domain to a sub domain with keeping the actual url in the browser on the sub domain?