I am having a scenario as following:
For example,I have a website http://www.example.com
, and I have setup a few subdomains such as http://video.example.com
, http://image1.example.com
, http://image2.example.com
. In Apache virtual host setting, they are using the same folder (e.g. /home/example/
). (these two domains have different bandwidth setup using mod_cband).
I have a subfolders /home/example/files/videos
, I want to make it only accessible from the subdomain http://video.example.com/files/videos/
but not from http://www.example.com/files/videos/
or any other subdomains.
How shall I configure this with a .htaccess
file?
Put this code in
/home/mywebsite/files/videos/.htaccess
You can check the host and then handle this with mod_rewrite creating a 301 redirect in an
.htaccess
file; although if you have access, it's much better if you do this in thehttpd.conf
or an included config file instead.Best Scenario
Since it looks like mod_cband wants a different virtualhost for each domain, you would setup your
httpd.conf
file something like this and include the rewrite rules in the config itself. Some web hosts will do this method where the main account site is theDocumentRoot
and the other sites are all nested under it's directory:Runner up
If you're using a hosting service provider where, you don't have access to the
httpd.conf
files, and they haven't setup the domains as analias
of the main domain (each domain has a separate folder), then you would write your rules in the root.htaccess
forwww.mywebsite.com
like this:Most overhead
If they are using aliases (where everything has the exact same document root) then you'll need to check the requested hostname with a
.htaccess
file that's commonly enacted by all: