I have a domain and an hosting that allows me to have as many subdomain as i need using cPanel.
I've created one called projects.test.com in which i upload all of my projects.
projects.test.com points to this specific path: public_html/projects
Now, my main domain, test.com, uses a 301 redirect to point to this path: public_html/home
and actually this bit is working, as if i type test.com, i'll be redirected to test.com/home.
Now, i have already write a question (here) on how to remove the /home from the url, and i though it was working. The only issue i've got with that, is that for some reason adding
RewriteEngine on
RewriteBase /
RewriteRule ^$ home/ [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?!home/).+)$ home/$1 [L,NC]
on my root .htaccess, it break the sub domain projects.test.com.
So my question is, how can i change this to make it work only for the main domain without breaking this sub domain i currently have and others that i could create in future?
And also, do i need to edit the root (intended as public_html folder, or the one one level above public_html?
Sorry but i'm new with all this type of server configuration and i'm still trying to learn.
Thanks for any advice
EDIT
The .htaccess file in my root is this:
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
<IfModule mod_setenvif.c>
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
</IfModule>
<IfModule mod_headers.c>
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>
</IfModule>
while the one in my public_html folder is:
RewriteOptions inherit
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/home
RewriteRule ^/(.*)$ /home$1 [L]
RewriteCond %{HTTP_HOST} ^test\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.test\.com$
RewriteRule ^/?$ "http\:\/\/www\.test\.com\/home" [R=301,L]
cPanel lets you put an addon or subdomain outside of (or above) the
public_htmldirectory. Since you've already created the subdomain, login to cPanel and click on the Subdomains link. In the Modify a Subdomain section, you can edit the Document Root. You'll need to do that and set the path to something like this:domains/projects.test.comDoing this will keep all of your addon and subdomains organized in a single folder, outside of the
public_htmldirectory, and avoid a lot of headaches down the road. The next time you create an addon or subdomain, you will do the same thing and set the Document Root todomains/sub.test.com.The absolute path to these addon and subdomains would be similar to this (except for the username and possibly the name of the
homedirectory):/home/<your_username>/domains/projects.test.com/And, of course, your primary domain (the one associated with your account), will always point here:
/home/<your_username>/public_html/With that issue resolved, if you want all requests sent to
homebut you don't want it to show up in the URL, your.htaccessfile (in yourpublic_htmldirectory) should look like this:You also mentioned that you have an
.htaccessfile in yourrootdirectory, which I assume you mean here:/home/<your_username>/.htaccessApache (or whatever HTTP server your host runs) will not read that file. Only files in your
public_htmldirectory (or other document root directories) are read.