.htaccess Cheat Sheet V1.0

ADVERTISEMENT

.htaccess
cheat sheet
v1.0
Apache
by Jean-Philippe Côté -
Configure allowed directives in .htaccess files (in main configuration file)
Block hotlinking
AllowOverride [ All | None ] | directive-list ...
Example :
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
Example :
AllowOverride All
(AuthConfig, FileInfo, Indexes, Limit, Option)
RewriteCond %{HTTP_REFERER} !^http://(www\.) [NC]
Assign default file (in specified order)
RewriteRule \.(gif|jpg)$ - [F]
Example :
DirectoryIndex default.html index.html index.php
To serve alternate content to hotlinkers, substitute last line above with :
RewriteRule \.(gif|jpg|png)$ [R,L]
Assign error message files (specify as many as needed)
ErrorDocument code document
Block access from specific referers
Examples :
ErrorDocument 401 /subscription.html
Example :
RewriteEngine on
ErrorDocument 403 "Sorry can't allow you access today"
RewriteCond %{HTTP_REFERER} [NC]
ErrorDocument 404 /errors/404.php
RewriteRule .* - [F]
ErrorDocument 500
Redirect to domain name without ‘www’ prefix
Redirect request
Example :
RewriteEngine On
Redirect [ status ] [ path ] [ url ]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
Examples :
Redirect oldpage.html /test/newpage.html
RewriteRule ^(.*)$ [R=301,L]
Redirect /olddir
Redirect permanent oldpage.html /test/newpage.html
Redirect to domain name with ‘www’ prefix
Redirect temp oldpage.html newpage.html
Example :
RewriteEngine On
Redirect gone oldpage.html
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ [R=301,L]
Enable / disable directory browsing
Examples :
Options +Indexes
(to enable)
Block access from specific IP blocks
Allow access only from specific IP blocks
Options -Indexes
(to disable)
Example :
order allow,deny
Example :
order deny,allow
deny from 123.45.6.7
deny from all
Hide files in directory browsing
deny from 12.34.5.
allow from 192.168.0.0/24
Examples :
IndexIgnore *.gif *.jpg
allow from all
allow from 10.0.
IndexIgnore *
Block access to a specific directory
Block access to specific files
Apply directives only to certain files or certain directories
Example :
<Directory /htdocs/test>
Example :
<files *.tmp>
<Directory /usr/local/httpd/htdocs/test>
Examples :
<files *.jpg>
order allow,deny
order allow,deny
Directives go here
directives go here
deny from all
deny from all
</Directory>
</files>
</Directory>
</files>
Modify PHP boolean or value parameters
Examples :
php_flag magic_quotes_gpc off
php_value upload_max_filesize 2M
Change script extensions
Apache HTTP Server 2 Directive Quick-Reference
AddType mime-type extension [extension] ...
Examples :
AddType application/x-httpd-php .gne
(.gne files will be parsed by PHP)

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go