How can I disable .php and .html files from my directory listing?
When someone visit my directory
http://example.com/dir
All other files except .php and html should be listed.
Add the following line to your .htaccess file
IndexIgnore *.html *.php
This tells the Apache web server to list all files except those that end with .php and .html .
If you want to disable all files and directories form listing ,Add this line to your .htaccess
IndexIgnore *
The wildcard '*' means it will not display any files
Related
I want to make a subfolder, named backups unreachable and files within it downloadable with the aid of .htaccess placed in the home directory. I don't want to create a secondary .htaccess file in the subfolder.
I did several rewrite and deny commands but no effect.
You can do the following with mod_rewrite at the top of the root .htaccess file to block (ie. 403 Forbidden) any requests to /backups or /backups/<anything>. For example:
RewriteEngine On
# Block any HTTP requests to "/backups" subdirectory
RewriteRule ^backups($|/) - [F]
Note that when used in .htaccess, the URL-path that then RewriteRule pattern matches against does not start with a slash.
Alternatively, use mod_authz_core inside an Apache expression to target just the /backups subdirectory. For example:
# Block any HTTP requests to "/backups" subdirectory
<If "%{REQUEST_URI} =~ m#^/backups($|/)#">
Require all denied
</If>
I would like to ask how is possible to redirect an non existent directory to a normal directory. Or even better, how is it possible to remove a directory from the url.
Example:
When the url is www.mysite.com/bad_directory/images/and/sub/directories I want it to be www.mysite.com/images/and/sub/directories. In other words I want the directory "bad_directory/" to be removed when directory "images" is requested.
You should add this line in your .htaccess file :
RewriteRule ^bad_directory/images/and/sub/directories$ /images/and/sub/directories [R,L]
Well I found the solution
At .htcaccess file, I added the line:
RedirectMatch ^/bad/directory/(.*)$ https://www.example.com/good-directory/$1
a while ago i was using htaccess to display some files, and recently i started that project again and found i had somehow deleted the "go up a level" button back then.
Can anyone tell me what the code line in htaccess looks like to get this button back? Should be relatively simple but i just cant find it... heres what i got.
Options +Indexes
# DIRECTORY CUSTOMIZATION
<IfModule mod_autoindex.c>
IndexOptions IgnoreCase FancyIndexing FoldersFirst NameWidth=* DescriptionWidth=* SuppressHTMLPreamble
# SET DISPLAY ORDER
IndexOrderDefault Descending Name
# SPECIFY HEADER FILE
HeaderName /partials/header.html
# SPECIFY FOOTER FILE
ReadmeName /partials/footer.html
# IGNORE THESE FILES, hide them in directory
IndexIgnore ..
IndexIgnore header.html footer.html icons
# IGNORE THESE FILES
IndexIgnore header.html footer.html favicon.ico .htaccess .ftpquota .DS_Store icons *.log *,v *,t .??* *~ *#
# DEFAULT ICON
DefaultIcon /icons/generic.gif
AddIcon /icons/dir.gif ^^DIRECTORY^^
AddIcon /icons/pdf.gif .txt .pdf
AddIcon /icons/back.png ..
</IfModule>
Options -Indexes
Okay found the problem, it was simple, just not very observant when looking at the code. The line "IndexIgnore .." roughly in the middle.
Example: wp_file*.log -- what that should do is to password protect every file whose filename start with wp_file and ends with .log -- for example wp_file-22.log and wp_file_randomfile.log.
Possible?
The way I would make this, is by adding a rewrite rule for those files, redirect to some PHP file with the origional request in the GET. The PHP file can than show a password box and eventually the content of the log file once logged in.
RewriteEngine On
RewriteRule wp_file(.*)\.log /somePHPfile.php?logFile=wp_file$1 [L]
(not tested)
If you dont need access to the log files via your website (but use e.g. ftp), than you can rewrite the requests to those files to another page
RewriteEngine On
RewriteRule wp_file(.*)\.log /index.php [L]
I have a directory with an .htaccess file having the setting IndexIgnore *. How can I set a subdirectory to not ignore anything, or to ignore the negation of everything, so as to override the parent directory's IndexIgnore? Like IndexIgnore ^*, only a working version thereof?
Simply add IndexIgnoreReset ON before the new IndexIgnore directive.
And then, to show everything in the sub folder use IndexIgnore "."
Check the documentation at:
IndexIgnoreReset
I don't think it will be possible because IndexIgnore list is always appended in the existing list (from parent .htaccess). There is now way to overwrite this directive AFAIK.
In <Directory> block you can add:
IndexIgnoreReset ON
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
This will override config for this specific <Directory>