I'm using cpanel to create addon domains for my account, the addon domains are created so that addon.com is put in the path /home/user/public_html/addon.com/ which means I can access them via primarydomain.com/addon.com. I'd like to cut off access to these directories so people can't access them outside of their domain
Add the following code in your .htaccess file at the root of addon.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.primarydomain\.com$
RewriteRule ^(.*)$ path/to/404/ErrorDoc
Alternative and far better: while creating addon.com specify the document root as outside the public_html folder. ie. /addon.com instead of /public_html/addon.com.
Hope that helps.
use htaccess and look at hostname and redirect if it wrong
Related
I am using Directnic to host multiple websites. Directnic, like many hosts, requires each website to be placed under the /home/<user>/public_html directory. And this works. My problem is that some websites are accessible from the "main" domain.
Here is an example of what my configuration looks like...
one.com is tied to the hosting plan, and is stored in public_html directly.
two.com is setup as an addon domain and is stored in public_html/two.
three.com is also setup as an addon domain and is stored in public_html/three.
This all works as expected, all three websites show three different websites and all have three different document roots, so everything works nicely.
My problem is that I can access the files for two.com and three.com by going to http://one.com/two/, etc, and I don't want this, I want them to be more isolated.
What configurations might I be able to make to hide these files from one.com?
My host uses Apache and cPanel, but I don't have access to specific conf files, so I can't create virtual hosts. Maybe some .htaccess trickery?
This is the way cPanel works. You cannot isolate it 100% and you will not get configuration access to add virtualhost entry. It is being managed by your service provider.
You can certainly restrict the access for HTTP. You can add rewrite rule in your subfoldess (in above example two and three folder). You can try the following .htaccess rewrite rules to prevent direct access from main domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?maindomain.com$ [NC]
RewriteCond %{REQUEST_URI} ^/addon1/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/addon2/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/addon3/(.*)$
RewriteRule ^(.*)$ - [L,R=404]
Once you add above rule, your main domain should not be able to access addon folder usin g HTTP. It should show 404 error page.
I've developed a website using Yii framework and now I need to move it to hostgator cheap hosting for a single site. It looks like it expects that the website must be placed into the root folder but my website has a www folder with index.php and resource files like js,css,images,etc. Also this folder contains a file htaccess with following content:
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
But I suppose I have to add another htaccess into the root folder so all requests will redirect to the www folder. (I did it and tried different combinations of the rewrite rules but they didn't work properly). I'm guessing I should remove htaccess from the www folder and leave only one in the root folder.
Sorry guys, I always have problems with htaccess even after reading documentation.
Thanks in advance.
I think that you can configure your domain as an addon domain with the document root set in www as you prefer.
Of course I am presuming that you have cPanel on Hostgator.
I'm the admin of an apache server (on a hosting package that allows me to host multiple domains), I've got one domain in public_html (let's call it www.ROOTwebsite.com) and 9 other domains hosted in a folder in the same directory level as the public_html, called DOMAINS.
So the structure is:
-DOMAINS/site1.com/
/site2.com/ ... etc
-public_html
I'm using '/' in the beginning of all relative paths in wamp for site1.com (for example /menu.php) and it works fine, but when I upload to DOMAINS/site1.com/ it messes up the site because it obviously is looking at the public_html directory as the ROOT.
I've used a number of combinations on the following in the .htaccess file, but I can't figure out which is the right syntax to change the ROOT to a directory sitting NEXT to public_html, not under it as usual:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.ROOTwebsite.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^ROOTwebsite.gr$
RewriteCond %{REQUEST_URI} !DOMAINS/site1.com/
RewriteRule (.*) /DOMAINS/site1.com/$1 [L]
I wish to change the root directory for site1.com so that it also works with the '/', without affecting the public_html website.
Can anyone see the problem with the code above?
You cannot redefine the document root via .htaccess. You have to create different vhosts for the domains that then can have separate document roots.
The closest I have come to redefine a document root via .htaccess is the following (not exactly what you are asking, because in my example, site1.com is a subdir of the main document root, but this would achieve what you want, with the caveat below).
RewriteCond %{HTTP_HOST} ^site1.com$ [NC]
RewriteRule !^site1.com/ /site1.com%{REQUEST_URI} [L,NC]
this will effectively redirect all site1.com to the site1.com subdirectory.
[caveat] The only problem I could not solve is how to redirect an url that goes directly to the subdirectory such as http://site1.com/site1.com/index.html to http://site1.com/index.html
I am trying to set up an .HTACCESS so I can have multiple domains with the same root directory. I want the htaccess to redirect to a php file dependant on domain name. I don't want to have to set it up per domain - I want it to be for any domain that I set up with the common root directory to redirect to its own php of the same name. eg
mydom1.co.uk will direct to mydom1.php ,
another.co.uk will direct to another.php
thanks in advance for any help
You can put the following in your .htaccess file at the document root:
RewriteEngine On
RewriteBase /
RewriteRule .* %{HTTP_HOST}.php [L,QSA]
However, I expect you'll need to amend the main rule to handle the request of different pages. At the moment everything will be rewritten to /domain.php
I hope this question is not redundant, but I could not find any answer to the exact question I am asking.
I own a multiple site shared hosting plan on a Linux server.
The hosting plan refers to a domain that we can call www.domain1.com
Every other domain is hosted as a subdir of the main domain. so for example domain2.com will be hosted like: www.domain1.com/domain2.com/
It could be reached using that path or using www.domain2.com directly.
I want to disable the access to domain2.com as subfolder of domain1.com.
I suppose I need to put a .htaccess file in every subfolder of domain1.com which is hosting a website. Am I correct? What do I have to put in the .htaccess file?
thank you in advance,
Max
Put these rules in the htaccess file in domain1's document root (the parent folder):
RewriteEngine On
RewriteCond %{HTTP_HOST} domain1\.com$ [NC]
RewriteRule ^(domain2\.com|domain3\.com)/ - [L,F]
Where the domain2\.com etc are the subfolders that you don't want to be able to have direct access.
However, if you have rewrite rules in each of those subfolders, then you do need to add rules in each of the subfolders:
RewriteCond %{HTTP_HOST} domain1\.com$ [NC]
RewriteRule - ^ [L,F]
The F flag will cause the request to return a 403 Forbidden.