100% found this document useful (1 vote)
279 views

Htaccess Cheat Sheet PDF

This document provides a cheat sheet of common directives that can be used in an .htaccess file to configure an Apache web server. It lists directives for configuring allowed directives, default files, error documents, redirects, directory browsing, hiding files, applying directives to certain files/directories, blocking hotlinking, blocking access from specific IPs/referrers, redirecting to/from www domains, and modifying PHP settings. The directives allow configuration of features like authentication, authorization, error handling and redirects without modifying the main server configuration file.

Uploaded by

cihat.yildiz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
279 views

Htaccess Cheat Sheet PDF

This document provides a cheat sheet of common directives that can be used in an .htaccess file to configure an Apache web server. It lists directives for configuring allowed directives, default files, error documents, redirects, directory browsing, hiding files, applying directives to certain files/directories, blocking hotlinking, blocking access from specific IPs/referrers, redirecting to/from www domains, and modifying PHP settings. The directives allow configuration of features like authentication, authorization, error handling and redirects without modifying the main server configuration file.

Uploaded by

cihat.yildiz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Apache

.htaccess cheat sheet v1.0

Congure allowed directives in .htaccess les (in main conguration le)


AllowOverride [ All | None ] | directive-list ...
Example :
AllowOverride All
(AuthCong, FileInfo, Indexes, Limit, Option)
Assign default le (in specied order)
Example :
DirectoryIndex default.html index.html index.php
Assign error message les (specify as many as needed)
ErrorDocument code document
Examples : ErrorDocument 401 /subscription.html
ErrorDocument 403 "Sorry can't allow you access today"
ErrorDocument 404 /errors/404.php
ErrorDocument 500 http://www.example.com/error
Redirect request
Redirect [ status ] [ path ] [ url ]
Examples : Redirect oldpage.html /test/newpage.html
Redirect /olddir http://www.domainname.com/newdir/
Redirect permanent oldpage.html /test/newpage.html
Redirect temp oldpage.html newpage.html
Redirect gone oldpage.html
Enable / disable directory browsing
Examples : Options +Indexes
(to enable)
Options -Indexes
(to disable)
Hide les in directory browsing
Examples : IndexIgnore *.gif *.jpg
IndexIgnore *
Apply directives only to certain les or certain directories
<Directory /usr/local/httpd/htdocs/test>
Examples : <les *.jpg>
Directives go here
directives go here
</Directory>
</les>

by Jean-Philippe Ct - www.cote.cc

Block hotlinking
Example :
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]
To serve alternate content to hotlinkers, substitute last line above with :
RewriteRule \.(gif|jpg|png)$ http://www.example.com/blocked.gif [R,L]
Block access from specic referers
Example :
RewriteEngine on
RewriteCond %{HTTP_REFERER} example\.com [NC]
RewriteRule .* - [F]
Redirect to domain name without www prex
Example :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Redirect to domain name with www prex
Example :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Block access from specic IP blocks
Example :
order allow,deny
deny from 123.45.6.7
deny from 12.34.5.
allow from all

Allow access only from specic IP blocks


Example :
order deny,allow
deny from all
allow from 192.168.0.0/24
allow from 10.0.

Block access to a specic directory


Example :
<Directory /htdocs/test>
order allow,deny
deny from all
</Directory>

Block access to specic les


Example :
<les *.tmp>
order allow,deny
deny from all
</les>

Modify PHP boolean or value parameters


Examples : php_ag magic_quotes_gpc o
php_value upload_max_lesize 2M
Change script extensions
AddType mime-type extension [extension] ...
Examples : AddType application/x-httpd-php .gne (.gne les will be parsed by PHP)

Apache HTTP Server 2 Directive Quick-Reference


http://httpd.apache.org/docs/2.0/mod/quickreference.html

You might also like