Htaccess: Difference between revisions
No edit summary |
|||
| Line 4: | Line 4: | ||
If you are presented with a download window when you click on a <code>.sh</code> or <code>.c</code> file, you may force the content to be a text file on apache by putting the following lines in your <code>.htaccess</code> file: | If you are presented with a download window when you click on a <code>.sh</code> or <code>.c</code> file, you may force the content to be a text file on apache by putting the following lines in your <code>.htaccess</code> file: | ||
{{highlight|lang=apache|code= | |||
AddType text/plain .sh | |||
AddType text/plain .c | |||
AddType text/plain .cpp | |||
}} | |||
== Hiding Specific Files from Directory Index == | == Hiding Specific Files from Directory Index == | ||
| Line 12: | Line 14: | ||
To hide specific files or directories from the directory index, use the <code>IndexIgnore</code> directive: | To hide specific files or directories from the directory index, use the <code>IndexIgnore</code> directive: | ||
{{highlight|lang=apache|code= | |||
IndexIgnore hidden_directory | |||
IndexIgnore "secret stash" | |||
IndexIgnore hidden_file.html | |||
}} | |||
As you would expect, enclose directory with spaces with quotes. | As you would expect, enclose directory with spaces with quotes. | ||
== Restricting Access by IP address == | |||
To allow certain IP address access: | |||
{{highlight|lang=apache|code= | |||
Order deny,allow | |||
Deny from all | |||
Allow from 172.20.1 | |||
Allow from 172.18.1 | |||
}} | |||
== Enabling Directory Index Header == | == Enabling Directory Index Header == | ||
| Line 26: | Line 38: | ||
== Enabling/Disabling Directory Index == | == Enabling/Disabling Directory Index == | ||
To enable: | To enable: | ||
{{highlight|lang=apache|code= | |||
Options +Indexes | |||
}} | |||
To disable: | To disable: | ||
{{highlight|lang=apache|code= | |||
Options -Indexes | |||
}} | |||
If the above doesn't work, ensure that your apache configuration allows override on directories. Eg: | If the above doesn't work, ensure that your apache configuration allows override on directories. Eg: | ||
{{highlight|lang=apache|code= | |||
<Directory /> | |||
Options FollowSymLinks | |||
AllowOverride All | |||
</Directory> | |||
}} | |||
[[Category:Linux]] | [[Category:Linux]] | ||
Revision as of 19:08, 13 January 2016
Forcing .sh, .c, .cpp as Text Files
If you are presented with a download window when you click on a .sh or .c file, you may force the content to be a text file on apache by putting the following lines in your .htaccess file:
AddType text/plain .sh
AddType text/plain .c
AddType text/plain .cpp
Hiding Specific Files from Directory Index
To hide specific files or directories from the directory index, use the IndexIgnore directive:
IndexIgnore hidden_directory
IndexIgnore "secret stash"
IndexIgnore hidden_file.html
As you would expect, enclose directory with spaces with quotes.
Restricting Access by IP address
To allow certain IP address access:
Order deny,allow
Deny from all
Allow from 172.20.1
Allow from 172.18.1
Enabling Directory Index Header
If you want your directory index to include a header file, use the HeaderName directive:
HeaderName header.html
Enabling/Disabling Directory Index
To enable:
Options +Indexes
To disable:
Options -Indexes
If the above doesn't work, ensure that your apache configuration allows override on directories. Eg:
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>