Does Apache have an option to disable directory listing globally? (But it will still allow me to use index.php as my main page)
Note: I have many virtual hosts and subdomains and what not.
Yes, its possible. You should use the Options directive with the -Indexes param
For example, in Centos /etc/httpd/conf/httpd.conf update Directory / to:
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.
<Directory />
Options FollowSymLinks -Indexes
AllowOverride None
</Directory>
This way all child configuration will enhirit this restriction.
Note that each child can override this if the directive AllowOverride is set to Indexes or All (This effect override params in .htaccess files)
Related
I've been spending all afternoon trying to solve this but couldn't by myself.
I've been trying in VSCode to implement an admin area by using .htaccess but the page will load without asking me anything.
I get no error whatsoever, neither do I in /var/log/httpd/error_log.
I modified AutoOverride in httpd.conf as such :
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
AllowOverride All
Require all denied
</Directory>
#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/srv/http"
<Directory "/srv/http">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
and uncommented LoadModule rewrite_module modules/mod_rewrite.so
Here's my .htaccess file :
RewriteEngine On
RewriteBase /
AuthName "Page d'administration protégée"
AuthType Basic
AuthUserFile "/home/badakzz/php/openclassroom/htdocs/sql/blog/admin/.htpasswd"
Require valid-user
I honestly don't know where to search anymore, I'm very new to Linux few people use Manjaro so they don't seem to have "/srv/http" as DocumentRoot (which I tried to copy my VSCode project into but it didn't change anything).
Thanks in advance for helping me in my misery...!
I would recommend the following Solution:
Edit the: /etc/httpd/conf/extra/httpd-userdir.conf file
Change:
AllowOverride Option1 Option2 Option3
to:
AllowOverride All
Save and restart apache:
sudo systemctl restart httpd
Test it.
I've just installed ubuntu-server_6.04.2_LTS, after the fresh installation I've enabled mod_rewrite, it's showing in phpinfo()
my .htaccess file is OK
but, still requests are not going through index.php
You should check if for that specific directory (root folder of your project), apache is configured to allow overriding through .htaccess.
If you want to allow such override, the directives found in apache.conf or the specific settings for your virtual host should look like this:
<Directory /var/www/>
AllowOverride All
Require all granted
</Directory>
I enabled mod_rewrite and want to redirect one of my local virtual host websites to google.com for practice.
I created an .htcaccess file in my virtual directory (/var/www/example.com/.htcaccess) and gave permissions to .htcaccess by adding the following code to my virtual host's (example.com) config in /sites-available/.
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
I am now attempting to use mod_rewrite by adding code to the .htcaccess file but have had no success thus far. Is there any way to check if .htcaccess is working? If it is, how do I redirect using mod_rewrite?
There is an typo. Normally the file name is .htaccess, not .htcaccess.
An other option is to set the file-name to you "personal style", like:
AccessFileName .htcaccess
http://httpd.apache.org/docs/2.2/howto/htaccess.html
Right now, I'm using Options -Indexes to hide access to all directory listings on a website of mine.
What I've discovered however is that I need directory access to a particular folder:
../Resource/Other/
Is there any way of applying a logical NOT rule to htaccess to allow access to certain folders, while disabling directory access by default? Or do I have to approach it from the other angle and enable directory listings globally and then selectively disable them folder by folder?
Create a htaccess file with Options +Indexes in the folder you want to list.
Be sure to remove any index files too.
the almost easiest way to do it is disabling listings globally and then allow list others. That is, your virtual host should be set up by default not to list directories when removing the "Indexes" option. Then you would add a Directory directive and set "Options" to allow listing of a particular directory.
For instance:
Say you have the following directory structure:
/home/user/www (note: www is the document root).
Into www directory there are appdir1, appdir2, app3 directories and you want list only appdir3 so in your virtualost:
<VirtualHost *:80>
DocumentRoot /home/user/www
ServerName myserver.local
<Directory /home/user/www/>
Options FollowSymLinks MultiViews
</Directory>
</VirtualHost>
In this case is not possible directory listing, any directories under document root is forbidden.
However, if you add other Directory directive you can set directory listing to specif dir:
<VirtualHost *:80>
DocumentRoot /home/user/www
ServerName myserver.local
<Directory /home/user/www/>
Options FollowSymLinks MultiViews
</Directory>
<Directory /home/user/www/appdir3>
Options Indexes
</Directory>
</VirtualHost>
On the other hand you can add .htaccess files to directories that you want allow directory listing.
In /home/user/www/appdir3/.htaccess add:
Options +Indexes
Also, if you runs Apache version 2.4+ you should take a look the <If> directive.
<If> Directive
I need help with EasyPHP and .htaccess .
The .htaccess file isn't working, I think its because I didn't setup something with EasyPHP.
My EasyPHP version is 5.3.8.1
Maybe anyone knows how to fix this problem ?
.htaccess file :
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^get/([^/]+) /func/get.php?link=$1 [NC]
Default installation of Apache in EasyPHP don't have activated the option to use .htaccess files to modify server configuration in folders.
You have to tell Apache what configuration can be changed with .htaccess files, and in which folder. To enable all config changes on main web server, you should edit http.conf (in Apache/conf folder), and look for:
<Directory "${path}/www">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
and change
AllowOverride None
to
AllowOverride All
To better fine tune it, read documentation about AllowOverride in:
http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride
Also, check that http.conf has mod_rewrite activated, look for:
#LoadModule rewrite_module modules/mod_rewrite.so
And remove the leading "#"
LoadModule rewrite_module modules/mod_rewrite.so
When working on a local website I fixed this problem by adding the website path (with the .htaccess) as a virtual host. Easyphp has got a module for this: 'Virtual Hosts Manager'. This wil automatically take care of the httpd.conf.