I have a root directory like:
- /var/www/html/
- index.html
- default_directory/
- index.html
I have many aliases that points on the default_directory, I need this because I have a single same website for many pages that serve different content based on url.
Can I deny access to that folder using httpd.conf or .htaccess but allowing aliases to access to it?
Related
I have the following folder structure on my apache server - the web root directory is /var/www/html and inside of it I have several websites:
/html
- website1.com
- website2.com
- website3.com
If I access the server via the IP address I can see the directories of all the websites on the server and even access them via the ip like: 5.5.5.5/website1.com
Is there a way to restrict the listing of the directories when accessed via the IP and prevent opening of subfolders via it, but still be able to access those website via the VirtualHosts. At the moment I have added the following via htaccess
root directory:
Satisfy all
Order deny,allow
Deny from all
subdirectories:
Satisfy all
Order deny,allow
Allow from all
that prevents getting a list of the subdirectories, but if you know the directory name you can still access it
I have a Google Compute Engine instance(installed apache, php, mysql etc.) and a custom domain name. I can do add my Custom Domain to my Google Compute Engine.
Lets my domain name be www.try.com .
my instance's "www" folder;
--->try
--->somethingelse2
--->somethingelse3
..
How can I set "www.try.com" access to only "try" folder? Thanks.
In deciding what file to serve for a given request, httpd's default behavior is to take the URL-Path for the request (the part of the URL following the hostname and port) and add it to the end of the DocumentRoot specified in your configuration files. Therefore, the files and directories underneath the DocumentRoot make up the basic document tree which will be visible from the web.
If a directory is requested (i.e. a path ending with /), the file served from that directory is defined by the DirectoryIndex directive. For example, if DocumentRoot were set as above, and you were to set:
DirectoryIndex index.html index.php
You only need to modify the path in the Directory index.
You can find more information here
I have a web setup where there are multiple sites under one directory... and one media folder containing images for each site...
www.domain1.com/media/domain1.com/
www.domain2.com/media/domain2.com/
As you can see domain1.com's media can be accessed from domain2 e.g. www.domain2.com/media/domain1.com/
and vice versa...
I want to restrict domain1 to access /media/domain2.com/ folder can it be done via htaccess file?
my idea was to somehow read the domain name and match it with the directory its trying to access...
or
alternatively can redirect all requests in media folder to a php script that can do the matching...?
Use VirtualHost for each domain and specify DocumentRoot for them, it will also remove the /media/domainN/ from URL.
If you want to perserve the document root for some reason, try using this in each VirtualHost directive:
<Directory "full/path/to/media/domain1.com">
deny from all
</Directory>
and vice-versa for domain2.
If I have a directory structure like this:
- index.php
- public
- img
- css
- application
- controllers
- user
- admin
- models
- views
.htaccess
I'm using the index.php as my front controller so all MVC classes and files are included and don't require directory access.
In the .htaccess I have Deny from all inside it and it sits in the application directory. Does that effectively deny direct file access and directory listing to all the sub-directories under the application directory as well? Or do I need to put the .htaccess file inside each sub-directory as well?
Many thanks
Yes - .htaccess works for the whole tree inside the directory. To override it's rules you have to add the given rule in a subdir and then the new .htaccess will work for the whole tree inside that subdir.
I have inherited a webserver already serving some websites. I am trying to migrate some of those sites to a new webserver.
One of those websites has a page called:
http://mydomain/ABCDepartment/
This URL also works:
http://mydomain/~joesmith
and the index page for joesmith actually lives in /var/www.../ABCDepartment/people/joesmith/
Now I am checking in httpd.conf and I see the following:
UseCanonicalName Off
UserDir public_html
UserDir disabled root
There are no special mod_rewrite rules for joesmith or the ~
How is this magic happening? UseCanonicalName is off, and if it wasn't UserDir public_html should look in /home/joesmith/public_html
What am I missing?
This is an Apache extension called userdir: http://httpd.apache.org/docs/1.3/mod/mod_userdir.html
It automatically rewrites requests to point to a folder called public_html within the user's home directory (the web server must have read access up the tree to this folder).