Anda di halaman 1dari 29

Memblok bot dan program crawler

Apabila Anda memiliki web server dengan bandwidth yang terbatas, alangkah baiknya bila Anda
mencegah bot atau program crawler lainnya (biasanya disebut spider) mengakses web Anda.
Perlu diketahui bahwa setiap request yang diterima oleh web server, selalu menyertakan
informasi User Agent. Bila melakukan browsing biasa, maka User Agent bisa berarti browser
yang digunakan oleh pengguna. Contoh kode yang bisa Anda gunakan adalah sebagai berikut.

?
<IfModule mod_rewrite.c>
1SetEnvIfNoCase ^User-Agent$
2.*(craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|
collector|grabber|webpictures) HTTP_SAFE_BADBOT
3SetEnvIfNoCase ^User-Agent$ .*(libwww-perl|aesop_com_spiderman)
4HTTP_SAFE_BADBOT
5Deny from env=HTTP_SAFE_BADBOT
</ifModule>

Untuk mengoptimalkan kode di atas, Anda harus memiliki daftar jenis User Agent yang memang
benar-benar bot atau crawler. Silahkan Anda tambahkan sendiri User Agent di kode tersebut
dengan mencari referensi di Internet.

Mengubah timezone server


Setting timezone server sangat menentukan ketika memanggil fungsi yang berhubungan dengan
waktu, seperti “mktime”. Bila setting yang ada di server tidak benar, akan muncul berbagai
masalah kevalidan waktu. Untuk itu, Anda bisa mengaturnya pada htaccess dengan kode sebagai
berikut.

?
1SetEnv TZ Australia/Melbourne

Daftar timezone yang bisa digunakan bisa Anda temukan pada alamat di bagian akhir artikel ini.

Mencegah penampilan daftar direktori


Biasanya, bila dalam sebuah folder web Anda tidak memiliki file index.html atau index.php,
maka secara default browser akan menampilkan daftar file dalam folder itu saat pengguna
mengaksesnya. Ini bisa jadi sebuah fitur yang bagus, namun terkadang bisa menyerempet ke
masalah keamanan data.
Contoh tampilan directory listing

Secara default, server XAMPP memperbolehkan akses daftar folder. Kode untuk
mengaktifkannya dalam htaccess adalah seperti berikut.

?
1Options +Indexes

Sedangkan untuk menonaktifkannya, Anda bisa menggunakan kode berikut.

?
1Options –Indexes

Htaccess tidak hanya sekedar mengaktifkan atau menonaktifkan saja. Bila Anda mengaktifkan
fitur directory listing, Anda juga bisa mencegah file tertentu untuk tidak ditampilkan. Contohnya
adalah sebagai berikut.

?
1IndexIgnore *.gif *.zip *.txt blog.html

Dengan demikian file berekstensi gif, zip, dan txt, serta file blog.html tidak akan ditampilkan
pada directory listing.

Redirect
Ada kalanya Anda ingin mengalihkan sebuah URL di website Anda ke alamat lainnya. Bisa jadi
alasannya adalah karena alamat lama terdapat di suatu folder tertentu, kemudian ingin
memindahkannya. Padahal sudah banyak pengguna yang menghafalkan alamat tersebut. Dengan
menggunakan htaccess, masalah tersebut dapat diatasi.

Cara termudah untuk melakukan redirect adalah sebagai berikut.

?
1Redirect /index.html /blog.html
Anda juga bisa melakukan redirect untuk keseluruhan folder.

?
1Redirect /folderlama /folderbaru

Cara yang lebih ampuh lagi melakukan redirect adalah menggunakan perintah RedirectMatch.

?
1RedirectMatch "\.html$" http://mimicreative.net/home

Pada perintah di atas, semua request terhadap alamat dengan akhiran “.html” akan diarahkan ke
alamat “home”.

Mengganti file default pada direktori


Setiap server memiliki aturan sendiri dalam menampilkan halaman default apabila kita
mengakses suatu direktori. Biasanya, yang akan diakses oleh server Apache bila kita mengakses
suatu direktori, pertama kali adalah file “index.html”, kemudian “index.php”. Berbeda lagi untuk
server lainnya.

Anda bisa mengubah file default dengan menggunakan htaccess. Caranya adalah sebagai berikut.

?
1DirectoryIndex home-page.html

Dengan demikian, apabila pengguna mengakses folder tanpa diikuti nama file, secara otomatis
akan diarahkan untuk mengakses file “home-page.html”. Anda juga bisa mengatur tidak hanya
satu file saja, tapi urutan file yang akan dicari seperti berikut.

?
1DirectoryIndex home-page.html index.html index.php

Dengan cara di atas, server akan mencari file secara berurutan dari “home-page.html”, yang bila
tidak ketemu akan dilanjutkan dengan pencarian “index.html”, yang kemudian akan mencari
“index.php”. Bila terdapat 2 nama file seperti “index.html” dan “index.php”, maka akan dipilih
yang paling kiri (sebagai prioritas).

Mengatur www atau non-www


Secara default, web server mengarahkan request baik www maupun root domain ke folder yang
sama. Jadi, Anda bisa mengakses alamat web Anda baik mimicreative.net ataupun
www.mimicreative.net. Yang menjadi masalah adalah bila terdapat 2 konten yang sama dengan
alamat yang berbeda, akan muncul pula pada search engine. Selain itu, akan membuat alamat
website Anda kurang konsisten.
Anda bisa mengatur apakah website Anda diharuskan memakai www ataupun tidak. Sebagai
contoh, website penulis, bila diakses menggunakan http://www.haqqi.net akan otomatis
mengarah ke root domain http://haqqi.net. Untuk melakukannya, dalam htaccess dituliskan kode
seperti berikut.

?
1RewriteEngine On
2RewriteCond %{HTTP_HOST} !^haqqi.net$ [NC]
3RewriteRule ^(.*)$ http://haqqi.net/$1 [L,R=301]

Sedangkan bila Anda menginginkan website Anda selalu menggunakan www apabila mengakses
root domain, maka kode htaccess-nya adalah sebagai berikut.

?
1RewriteEngine On
2RewriteCond %{HTTP_HOST} ^haqqi.net [NC]
3RewriteRule ^(.*)$ http://www.haqqi.net/$1 [L,R=301]

Langkah ini cukup penting, mengingat masih banyak orang awam yang mengakes root domain
dengan awalan sub-domain www. Sedangkan untuk pilihan apakah alamat yang Anda gunakan
adalah www ataupun non-www, semua ada di tangan Anda.

Kompresi file
Salah satu perintah yang cukup bermanfaat lainnya adalah kompresi file yang dikirim dari server
ke pengguna. Htaccess mampu melakukannya, dengan beberapa baris saja. Kompresi yang
digunakan adalah zlib, berikut contoh kode-nya.

?
1
2 # compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
3 AddOutputFilterByType DEFLATE text/html
4 AddOutputFilterByType DEFLATE text/xml
5 AddOutputFilterByType DEFLATE text/css
6 AddOutputFilterByType DEFLATE application/xml
7 AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
8 AddOutputFilterByType DEFLATE application/javascript
9 AddOutputFilterByType DEFLATE application/x-javascript
10

Kode di atas akan mengkompres file teks, html, javascript, css, dan xml. Anda bisa
menambahkan jenis file lainnya selama Anda mengerti jenis file atau mime-type file yang akan
Anda kompres.

Cache File
Mekanisme caching dapat mempercepat akses website karena file yang di-cache tidak perlu
diproses lagi. Cara ini cukup efektif terutama bila website Anda memiliki pengguna tetap.
Pengguna akan mengakses file ter-cache alih-alih mendownload file yang sama lagi. Cache bisa
terletak di server maupun komputer pengguna. Berikut ini contoh kode untuk men-cache
beberapa tipe file.

?
1<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$">
2Header set Cache-Control "max-age=2592000"
3</FilesMatch>

Anda bisa mengubah seberapa lama cache akan disimpan dengan mengatur parameter “max-
age”. Pastikan Anda men-cache hanya jenis file yang sangat jarang sekali berubah, karena
terkadang ada file yang bersifat dinamis. File script seperti PHP sebaiknya tidak di-cache,
terutama bila Anda cukup sering mengubah-ubah file PHP tersebut.

Untuk menghindari cache pada script dan file-file dinamis lainnya, Anda bisa menggunakan
kode berikut ini.

?
1<FilesMatch ".(pl|php|cgi|spl|scgi|fcgi)$">
2Header unset Cache-Control
3</FilesMatch>

Dengan demikian, maka file tersebut tidak akan di-cache oleh server maupun browser pengguna.
Setiap kali pengguna mengakses file tersebut, browser akan selalu mendownload yang terbaru.

Mengatur MIME Types


MIME Type mengatur tentang jenis apakah sebuah file tersebut, atau secara sederhananya adalah
sebuah ekstensi file sebagai acuan jenis file tersebut. Sebagai contoh, file “.html” berarti file
tersebut adalah sebuah dokumen HTML, file “.zip” berarti file tersebut adalah arsip ZIP, dan
sebagainya. Terkadang web hosting yang ada, tidak melakukan pengaturan MIME Types secara
benar. Untuk mengubahnya, Anda bisa menambahkannya melalui htaccess seperti berikut.

?
1
AddType application/rtf .rtf
2AddType image/gif .gif .GIF
3AddType image/ief .ief
4AddType image/jpeg .jpeg .jpg .jpe .JPG
5AddType image/tiff .tiff .tif
6AddType application/zip .zip
AddType application/x-mif .mif
7
Ada berbagai jenis MIME yang bisa Anda lihat pada alamat di akhir artikel ini. Berbagai trik
juga bisa diterapkan, seperti trik untuk masalah file MP3 atau SWF yang tidak dijalankan, Anda
bisa mengatur MIME Type seperti berikut.

?
1AddType application/x-shockwave-flash .swf

Trik lain, beberapa browser mungkin akan menampilkan jenis file tertentu di browser tersebut,
seperti file PDF ataupun Word. Untuk “memaksa” browser agar langsung melakukan download,
Anda bisa mengatur MIME Types dari extensi suatu file menjadi “application/octet-stream”,
seperti berikut.

?
1AddType application/octet-stream .pdf .doc

Bisa dilihat pula pada contoh di atas, Anda bisa mendeklarasikan beberapa ekstensi pada satu
baris.

Penutup
Masih banyak trik yang dapat dilakukan dengan htaccess ini. Manfaat yang bisa didapat pun
berbagai ragam. Namun perlu Anda ingat sekali lagi, bahwa perintah dalam root folder htaccess
akan berdampak pula pada folder di dalamnya. Jadi, berhati-hatilah terhadap pedang bermata dua
yang bisa membingungkan Anda ini. Selamat mencoba.

Tabel Response Code


Setiap proses request, server Apache selalu memberikan response code di http header, agar
browser dapat memilah mana yang sukses dan mana yang error. Berikut ini adalah daftar
response code yang umum digunakan.

Successful Client Requests


200 OK
201 Created
202 Accepted
203 Non-Authorative Information
204 No Content
205 Reset Content
206 Partial Content

Client Request Redirected


300 Multiple Choices
301 Moved Permanently
302 Moved Temporarily
303 See Other
304 Not Modified
305 Use Proxy

Client Request Errors


400 Bad Request
401 Authorization Required
402 Payment Required (not used yet)
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable (encoding)
407 Proxy Authentication Required
408 Request Timed Out
409 Conflicting Request
410 Gone
411 Content Length Required
412 Precondition Failed
413 Request Entity Too Long
414 Request URI Too Long
415 Unsupported Media Type

Server Errors
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported

Memanfaatkan .htaccess untuk konfigurasi website


Posted by kusprayitna on January 24th, 2009

Dalam konfigurasi webserver yang menggunakan scripting PHP, baik itu versi 4 ataupun 5
sangatlah mudah, yaitu dengan melakukan konfigurasi di php.ini. Di OS Windows maupun linux
dan sejenisnya adalah sama.
Misalnya untuk mengaktifkan register_globals=on cukup mengganti saja di php.ini, akan tetapi
akan menjadi sedikit kendala apabila kita bukan super user pada mesin tersebut. Karena kita
tidak bisa akses mengganti konfigurasi php.ini, misalnya website anda pada server hostingan.

Atau dalam kasus lain, anda adalah super user dalam sebuah server web dan dalam server
tersebut diinstall beberapa aplikasi, misalnya cms, ada yang membutuhkan register_global aktif
dan ada yang mengharuskan register_global tidak aktif. Bagaimanakah solusinya?

Di dalam apache terdapat file .htaccess yang dapat berisi konfigurasi-konfigurasi yang dapat
melakukan override/menimpa seting di php.ini, inilah yang dapat dimanfaatkan.

Contoh pemanfaatan .htaccess:

1. Tidak menampilkan daftar file/folder di web jika tidak ada file indexnya (index.php,
index.htm, dll)

Options -Indexes

2. Menentukan IP yang tidak boleh akses ke web

deny from 000.000.000.000

000.000.000.000 dapat diganti dengan alamat IP


Apabila hanya beberapa IP yang diisikan, berarti IP yang tidak disebutkan boleh akses ke
web

3. Menentukan IP yang boleh akses ke web

allow from 000.000.000.000

000.000.000.000 dapat diganti dengan alamat IP


Apabila alamat IP yang ditentukan hanya beberapa saja, maka akan menyebabkan IP
yang tidak disebutkan menjadi tidak dapat akses ke website

deny from all

Dapat digunakan untuk melakukan penolakan akses semua user di web

4. Mengganti file index yang sudah ditentukan di apachePada umunya webserver sudah
menentukan file-file index yang biasa dipakai dan apabila tidak didapat salah satu file
tersebut maka listing file/folder ditampilkan. Apabila diinginkan menampilkan file index
dengan nama lain, mislanya “utama.php”, maka ini dapat dilakukan dengan membuat
alternatif index

DirectoryIndex index.php index.php3 index.html index.htm utama.php


5. Memindahkan / redirectMisalnya sebuah folder dalam website sebelumnya adalah /news,
dan karena ada perubahan maka aplikasi diupdate dan dipasang di /new_news dengan
tidak merubah /news yang lama. Ini dapat dilakukan dengan melakukan redirect folder
/news ke /new_news, misalnya dari browser diakses http://x.x.x.x/news/index.php maka
dengan redirect ini akan otomatis diganti menjadi http://x.x.x.x/new_news/index.php
(termasuk semua sub folder di dalamnya)

Redirect /news http://x.x.x.x/new_news

dapat juga digunakan hanya untuk sebuah file saja, misalnya /index.php dipindahkan ke
/baru/index.php

Redirect /index.php http://x.x.x.x/baru/index.php

6. Melakukan override php.iniSeting di php.ini dapat di override , contoh sebagai berikut :

php_flag register_globals off


php_value post_max_size 32M
php_value mbstring.func_overload 0

7. Melindungi website dengan passwordTerkadang dalam aplikasi berbasis internet tidak


disediakan fasilitas otentifikasi/autorisasi sesuai yang kita inginkan, untuk menambahkan
atau merubah keamanan website dapat juga digunakan .htaccess ini.

AuthName “Member Area”


AuthType Basic
AuthUserFile /full/path/to/.htpasswd
Require valid-user

Auth name diberi nama Member Area


AuthUserFile diisi dengan tempat file user:password disimpan

Untuk file /full/path/to/.htpasswd berisi data dengan format berikut :

username:password

Dengan penambahan perlindungan website dengan password ini, maka website sekarang
dapat dibuka dengan

http://username:password@www.website.com/directory/

Selamat mencoba dan semoga bermanfaat


General

Mengenal Konfigurasi .htaccess


An article by Purba Kuncara 3 Comments

Ada bagian yang kelihatannya sepele tapi banyak kegunaannya untuk keberlangsungan website
Anda. Yaitu sebuah file yang bernama .htaccess.

File .htaccess adalah sebuah file teks ASCII sederhana. Anda bisa membuat atau mengedit file
ini di Text Editor (Notepad) dan kemudian mengunggahnya ke direktori yang ingin anda setting.

Perintah-perintah di dalam file .htaccess mempengaruhi direktori tempatnya berada dan semua
subdirektorinya. Bila anda meletakkan file .htaccess di public_html, maka hal tersebut akan
mempengaruhi semua website anda.

1. Mengarahkan akses namadomain tanpa WWW ke WWW

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domainanda.com [nc]
rewriterule ^(.*)$ http://www.domainanda.com/$1 [r=301,nc]

2. Mencegah orang lain melihat htaccess dan file lainnya


order allow,deny
deny from all

Jika anda mau mencegah pengaksesan file lain, ganti nama file .htaccess dengan nama file yang
lain.

3. Mengubah Pesan Error


Jika anda ingin mengubah halaman error server, anda bisa menggunakan .htaccess untuk
mendefinisikan pesan error anda sendiri. Contoh syntax ini adalah:

ErrorDocument 500 /error.html

Isi error.html dengan halaman yang berisikan ERROR.

4. Blok IP tertentu atau pengunjung yang diarahkan dari web lain untuk mengakses web
Anda

Jika anda ingin mem-blok access untuk beberapa individu dan anda mengetahui IP / domain
name yang digunakan, tambahkan baris berikut :
order deny,allow
deny from 123.456.789.000
deny from 456.78.90.
deny from .capekdeh.com
allow from all
Pada contoh di atas, user dg IP 123.456.789.000 akan diblok. Semua user antara 456.78.90.000
sampai 456.78.90.999 akan diblok. Dan semua user yang terhubung dari capekdeh.com akan
diblok. Jika mereka mencoba mengakses situs Anda, maka akan tampil error 403 Forbidden
(“You do not have permission to access this site”).

5. Mengarahkan pengunjung ke halaman baru atau direktori baru

Misalnya bila halaman lama Anda adalah halamanlama.html dan halaman baru adalah
halamanbaru.html, maka perintahnya adalah:

Redirect permanent /halamanlama.html http://www.domainanda.com/halamanbaru.html

Jika anda mengubah nama direktori, maka perintahnya adalah:

Redirect permanent /direktorilama http://www.domainanda.com/domainbaru/

Perhatikan bahwa nama direktori yang lama ditulis dengan “relative path”, sementara yang baru
ditulis dengan “URL absolut” (dengan tanda “/”

6. Mencegah “Hot Linking” dan “Bandwidth Leeching”

Untuk mencegah orang lain melink secara langsung ke direktori image atau file anda dari
website mereka sehingga mencuri bandwidth Anda, maka gunakan:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domainanda.com/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ – [F]
Perintah tersebut akan membuat direktori image hanya bisa diakses bila user sedang mengakses
www.domainanda.com

Anda jugabisa membuat sebuah gambar bila direktori image Anda dilink. Contohnya image
jangandicuri.gif yang bertuliskan: “Mencuri membuat Anda sakit … kunjungi
http://domainanda.com untuk melihat gambar yang kami miliki”, maka gunakan perintah:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domainanda.com/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ http://www.domainanda.com/jangandicuri.gif [R,L]

7. Melindungi WP-Comment-Post.php dari spam

Walaupun ada Akismet, tapi mungkin perlu juga Anda melindungi blog Anda dari serangan
spambot yang mencoba mengirim komentar spam langsung melalui wp-comment-post.php tanpa
mengakses blog kita.

RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

8. Melindungi WP-Config.php

Melindungi file wp-config.php yang berisi informasi nama database, username database, dan
password database anda.

# protect wpconfig.php
<files wp-config.php>
order allow,deny
deny from all
</files>

Beranda >> SEO >> Mengenal htaccess dan fungsinya

Mengenal htaccess dan fungsinya

File .htaccess adalah file konfigurasi yang disediakan oleh web server Apache, yang biasanya
digunakan untuk mengubah pengaturan default dari Apache. Kita ketahui bahwa sebagian besar
web hosting di internet menggunakan Apache sebagai servernya sehingga bagi para pengelola
web / webmaster sedikit banyak harus belajar tentang .htaccess agar kita bisa mengubah
pengaturan default dari server. File .htaccess merupakan file teks ASCII sederhana yang
biasanya diletakkan dalam root direktori. File ini diharuskan dalam format ASCII dan bukan
binary dan untuk file permission (atribut file) pada server hosting harus di set 644 (rw-r-r). Hal
tersebut dimaksudkan agar server dapat mengakses file .htaccess, tapi mencegah user untuk
mengakses file .htaccess dari browser mereka. File .htaccess yang diletakkan dalam root
direktori dapat digunakan untuk mengubah konfigurasi dari subdirektori-subdirektori yang ada
didalamnya, sehingga dalam satu website biasanya kita cukup untuk mempunyai 1 file .htaccess
saja yang diletakkan dalam root direktori.

Kode perintah dalam file .htaccess harus ditempatkan dalam satu baris, jadi apabila kita
membuat file .htaccess dengan menggunakan text editor seperti notepad maka kita harus
mendisable fungsi word wrap (memotong baris) terlebih dahulu.

Kegunaan File .htaccess

File .htaccess dapat digunakan antara lain untuk :

1. Custom HTTP Error

Pesan error pada sebuah website sangat penting karena bisa membantu para pengunjung dalam
mengetahui apa yang sedang terjadi. Dengan htaccess kita dapat mengubah halaman error pada
server, dengan mendefinisikan sesuai dengan keinginan kita sendiri. Contohnya yaitu pengalihan
pesan sesuai fungsinya seperti berikut :

ErrorDocument 400 /errors/400.html


ErrorDocument 401 /errors/401.html
ErrorDocument 403 /errors/403.html
ErrorDocument 404 /errors/404.html
ErrorDocument 500 /errors/500.html

2. Override SSI Settings

Secara default, hanya halaman web yang mempunyai extensi .shtml yang bisa menjalankan
server-side termasuk SSI di server. Dengan menggunakan .htaccess kita dapat mengubah setting
default tersebut agar SSI bisa bekerja dengan format HTML.

Untuk mengubah pengaturan tersebut, kita dapat menambahkan kode berikut di file .htaccess

AddType text/html .html


AddHandler server-parsed .html

Jika kita menginginkan halaman yang berekstensi .html dan .htm untuk dapat menjalankan SSI,
maka file .htaccess dapat ditambahkan kode berikut

AddType text/html .html


AddHandler server-parsed .html
AddHandler server-parsed .htm

3. Change Default Home Page

artinya bahwa file .htaccess dapat digunakan untuk mengubah nama default halaman depan web.
Agar user bisa mengakses website kita hanya dengan nama domain saja
(http://www.nama_web.com) tanpa harus menulis nama file secara jelas
(http:www.nama_web.com/file.html), kita harus mempunyai file index di root direktori. Nama
file yang bisa diterima antara lain index.html, index.htm, index.cgi, index.php dll. Pastikan
bahwa file tsb bernama index.*

Ada tingkatan dalam pemberian nama tersebut. Jika kita punya index.cgi & index.html di root
direktori maka server akan menampilkan index.cgi karena .cgi memiliki tingkatan yang lebih
tinggi daripada .html

Dengan .htaccess, kita bisa mendefinisikan file index tambahan atau bisa juga mengubah urutan
tingkatannya. Untuk mendefinisikan mainpage.html sebagai halaman index, kita dapat
menambahkan kode berikut ke file .htaccess

DirectoryIndex mainpage.html

Hal ini akan membuat server mencari file bernama mainpage.html. Jika server menemukannya
maka server akan menampilkannya. Tapi bila tidak, maka server akan menampilkan error 404
Missing Page

Untuk mengubah urutan tingkatan, kita dapat memasukkan perintah DirectoryIndex dengan
nama-nama file dalam satu baris. Urutan penulisan file tersebut menentukan urutan tingkatan,
contohnya:

DirectoryIndex mainpage.html index.cgi index.php index.html

4. Enable Directory Browsing

Untuk alasan keamanan, server Apache biasanya telah menghilangkan default setting yang
memungkinkan directory indexing. Opsi inilah yang memungkinkan isi dari direktori untuk
ditampilkan di browser jika direktori tersebut tidak mempunyai halaman index.

Contohnya, jika kita memasukkan sebuah UR yang tidak mempunyai halaman index seperti
misalnya http://domainanda.com/images/, maka browser akan menampilkan daftar images di
dalam direktori tersebut

5. Block Users from Accessing Your Web Site

Jika kita menginginkan mem-blok access untuk beberapa user, dimana kita mengetahui IP /
domainname yang digunakannya, kita dapat menambahkan kode berikut :

order deny,allow
deny from 123.456.789.000
deny from 456.78.90.
deny from .aol.com
allow from all

Pada contoh di atas, user dg IP 123.456.789.000 akan diblok. Semua user antara 456.78.90.000
sampai 456.78.90.999 akan diblok. Dan semua user yang berasal dari AOL.com akan diblok.
Jika mereka mencoba mengakses website kita, maka akan tampil error 403 Forbidden (”You do
not have permission to access this site”)

6. Redirect Visitors to a New Page or Directory

Misalkan kita membuat ulang seluruh website kita, me-rename halaman & direktori. Maka
pengunjung halaman lama akan mendapat error 404 File Not Found. Masalah tersebut dapat
diatasi dengan melakukan redirect dari halaman lama ke halaman yang baru. Contohnya bila
halaman lama kita adalah oldpage.html dan halaman baru adalah newpage.html maka
perintahnya adalah:

Redirect permanent /oldpage.html http://www.mydomain.com/newpage.htm

Jika kita me-rename (mengganti nama) direktori, maka perintahnya adalah:

Redirect permanent /olddirectory http://www.mydomain.com/newdirect

Perhatikan bahwa nama direktori yang lama ditulis dengan relative path, sementara yang baru
ditulis dengan URL absolut

7. Prevent Hot Linking and Bandwidth Leeching

Untuk mencegah orang lain me-link secara langsung ke direktori image anda dari website
mereka, biasanya ada orang mengambil gambar dari website kita, tapi tetap menggunakan link
diserver host kita, ini tentu akan merugikan bagi kita karena dapat mengurangi bandwith di
hosting kita, untuk mengatasi hal ini kita dapat menambahkan kode berikut:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?namadomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]

Perintah tersebut akan membuat direktori image hanya bisa diakses bila user sedang mengakses
www.namadomain.com

Jika kita merasa jengkel, kita bisa membuat sebuah image alternatif bila direktori image di-link
oleh orang lain. Contohnya kita membuat image alternatif dengan nama nogambar.gif yang
bertuliskan: “Gambar dr web lain … kunjungi http://namadomain.com untuk melihat gambar
sebenarnya.” Maka kita dapat menambahkan kode berikut:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.mydomain.com/dontsteal.gif [R,L]

8. Prevent viewing of .htaccess or other files

Untuk mencegah user mengakses file .htaccess, ketikkan perintah:

order allow,deny
deny from all

9. Rewriting URLs

Agar kita dapat melakukan pengaturan pada permalink kita agar lebih SEO friendly kita dapat
menambahkan kode berikut ini:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

10. MIME types

Memerintahkan server untuk mengenali jenis file-file yang belum didaftarkan dalam sistem
server. Contohnya :

AddType application/octet-stream .doc .xls .pdf

11. Cache Control

htaccess bisa mengendalikan caching pada web browser sehingga dapat mengurangi penggunaan
bandwidth atau aktivitas yang ada didalam server. Contohnya :

# 480 weeks
Header set Cache-Control "max-age=290304000, public"
# 2 DAYS
Header set Cache-Control "max-age=172800, public, must-revalidate"
# 2 HOURS
Header set Cache-Control "max-age=7200, must-revalidate"

Dari beberapa kegunaan dari file .htaccess diatas, kita dapat kembangkan sesuai dengan
kebutuhan kita.

Contoh penerapan htaccess pada php bisa anda baca pada tutorial Membuat clean url dengan php

Semoga bermanfaat
#############################################################################
##
## The Master .htaccess
##
## Version 2.5 (proposed) - May 16th, 2011
##
## ----------
## This file is designed to be the template .htaccess file to put on your new
## sites, increasing your site's security and performance. It is not meant to
## be just dropped in your site, though. You should go through all of its
## sections and modify it to match your site. Most notably, all instances of
## example.com and example\.com should be replaced with your real domain
name.
##
## Some sections are too picky and may cause problems with legitimate
requests.
## You are ultimately responsible for disabling them or writing exception
rules
## for your requests. Most notably, the advanced server protection section
will
## cause issues with several minifiers, eXtplorer, VirtueMart and other
exten-
## sions which use non-standard scripts as their entry points. You must add
## exceptions for them manually.
##
## Some sections - depending on your server configuration - may cause your
site
## to throw 500 Internal Server Error. The only way to figure out which one
is
## causing it is trial and error.
##
## Big thank you's to Brian Teeman, Ken Crowder, Radek Suski and Fotis
## Evangelou for sharing their .htaccess rules with the world and inspiring
## the creation of this file. Special thanks to Jon Brown for sharing his
## research and helping me improve this file.
##
## Additional thank-yous to John for his remarks and g1smd for taking the
## time to optimize the speed of the file.
##
## It is usually prudent to remove the comments from the file when using it
## on a live host to minimize the parsing time.
##
## ----------------------------------------------------------------------
## Do you want to customize this .htaccess file with a few clicks?
## Admin Tools Professional by AkeebaBackup.com does this and much more.
##
## Learn more: http://www.akeebabackup.com/software/admin-tools.html
## ----------------------------------------------------------------------
##
## Have fun, stay safe.
##
## Nicholas K. Dionysopoulos
## Lead Developer, AkeebaBackup.com
##
## CHANGELOG:
## Version 2.5 (proposed) (May 16th, 2011)
## - Placeholders for custom code. Correction of ruleset ordering.
## Version 2.4 (April 18th, 2011)
## - Dozens of speed optimisations and many logic and syntax corrections.
## Version 2.3 (November 18th, 2010)
## - Added .ico to the pass-through rules, for favicons to load
## Version 2.2 (October 25th, 2010)
## - Bug in the tmpl=component rule
## Version 2.1 (October 19th, 2010)
## - index.php to root redirection would kill some AJAX requests
## - Referer filtering was screwed up
## - Simplified and more thorough PHP Easter Egg code (thanks Jon!)
## - The tp/template/tmpl filter was not thorough and killed some components
## - Optimized Joomla! core SEF section
## - Bot filters and GZip optimization would never run for dynamic content
## - Content expiration optimization got more optimized
## - Added ETag rule
##
#############################################################################
##

########## Begin - RewriteEngine enabled


RewriteEngine On
########## End - RewriteEngine enabled

########## Begin - RewriteBase


# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root)

# RewriteBase /
########## End - RewriteBase

########## Begin - No directory listings


## Note: +FollowSymlinks may cause problems and you might have to remove it
IndexIgnore *
Options +FollowSymLinks All -Indexes
########## End - No directory listings

########## Begin - File execution order, by Komra.de


DirectoryIndex index.php index.html
########## End - File execution order

########## Begin - ETag Optimization


## This rule will create an ETag for files based only on the modification
## timestamp and their size. This works wonders if you are using rsync'ed
## servers, where the inode number of identical files differs.
## Note: It may cause problems on your server and you may need to remove it
FileETag MTime Size
########## End - ETag Optimization

########## Begin - Common hacking tools and bandwidth hoggers block


## By SigSiu.net and @nikosdion.
# This line also disables Akeeba Remote Control 2.5 and earlier
SetEnvIf user-agent "Indy Library" stayout=1
# WARNING: Disabling wget will also block the most common method for
# running CRON jobs. Remove if you have issues with CRON jobs.
SetEnvIf user-agent "Wget" stayout=1
# The following rules are for bandwidth-hogging download tools
SetEnvIf user-agent "libwww-perl" stayout=1
SetEnvIf user-agent "Download Demon" stayout=1
SetEnvIf user-agent "GetRight" stayout=1
SetEnvIf user-agent "GetWeb!" stayout=1
SetEnvIf user-agent "Go!Zilla" stayout=1
SetEnvIf user-agent "Go-Ahead-Got-It" stayout=1
SetEnvIf user-agent "GrabNet" stayout=1
SetEnvIf user-agent "TurnitinBot" stayout=1
# This line denies access to all of the above tools
deny from env=stayout
########## End - Common hacking tools and bandwidth hoggers block

########## Begin - Automatic compression of resources


# Compress text, html, javascript, css, xml, kudos to Komra.de
# May kill access to your site for old versions of Internet Explorer
# The server needs to be compiled with mod_deflate otherwise it will send
HTTP 500 Error.
# mod_deflate is not available on Apache 1.x series. Can only be used with
Apache 2.x server.
# AddOutputFilterByType is now deprecated by Apache. Use mod_filter in the
future.
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css
application/xml application/xhtml+xml application/rss+xml
application/javascript application/x-javascript
########## End - Automatic compression of resources

########## Begin - Add optional bad user agent or IP blocking code


#
# If you need to block certain user agents or IP addresses and
# other signatures, place that code here. Ensure the rules use
# the correct RewriteRule syntax and the [F] flag.
#
########## End - Add optional bad user agent or IP blocking code

########## Begin - Rewrite rules to block out some common exploits


## If you experience problems on your site block out the operations listed
below
## This attempts to block the most common type of exploit `attempts` to
Joomla!
#
# If the request query string contains /proc/self/environ (by SigSiu.net)
RewriteCond %{QUERY_STRING} proc/self/environ [OR]
# Block out any script trying to set a mosConfig value through the URL
# (these attacks wouldn't work w/out Joomla! 1.5's Legacy Mode plugin)
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode or base64_decode data within
the URL
RewriteCond %{QUERY_STRING} base64_(en|de)code[^(]*\([^)]*\) [OR]
## IMPORTANT: If the above line throws an HTTP 500 error, replace it with
these 2 lines:
# RewriteCond %{QUERY_STRING} base64_encode\(.*\) [OR]
# RewriteCond %{QUERY_STRING} base64_decode\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
########## End - Rewrite rules to block out some common exploits

########## Begin - File injection protection, by SigSiu.net


RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=http:// [OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=(\.\.//?)+ [OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=/([a-z0-9_.]//?)+ [NC]
RewriteRule .* - [F]
########## End - File injection protection

########## Begin - Basic antispam Filter, by SigSiu.net


## I removed some common words, tweak to your liking
## This code uses PCRE and works only with Apache 2.x.
## This code will NOT work with Apache 1.x servers.
RewriteCond %{QUERY_STRING}
\b(ambien|blue\spill|cialis|cocaine|ejaculation|erectile)\b [NC,OR]
RewriteCond %{QUERY_STRING}
\b(erections|hoodia|huronriveracres|impotence|levitra|libido)\b [NC,OR]
RewriteCond %{QUERY_STRING}
\b(lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby)\b [NC,OR]
RewriteCond %{QUERY_STRING}
\b(ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo)\b [NC]
## Note: The final RewriteCond must NOT use the [OR] flag.
RewriteRule .* - [F]
## Note: The previous lines are a "compressed" version
## of the filters. You can add your own filters as:
## RewriteCond %{QUERY_STRING} \bbadword\b [NC,OR]
## where "badword" is the word you want to exclude.
########## End - Basic antispam Filter, by SigSiu.net

########## Begin - Advanced server protection - query strings, referrer and


config
# Advanced server protection, version 3.2 - May 2011
# by Nicholas K. Dionysopoulos

## Disallow PHP Easter Eggs (can be used in fingerprinting attacks to


determine
## your PHP version). See http://www.0php.com/php_easter_egg.php and
## http://osvdb.org/12184 for more information
RewriteCond %{QUERY_STRING} \=PHP[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-
f]{4}-[0-9a-f]{12} [NC]
RewriteRule .* - [F]

## SQLi first line of defense, thanks to Radek Suski (SigSiu.net) @


## http://www.sigsiu.net/presentations/fortifying_your_joomla_website.html
## May cause problems on legitimate requests
RewriteCond %{QUERY_STRING} concat[^\(]*\( [NC,OR]
RewriteCond %{QUERY_STRING} union([^s]*s)+elect [NC,OR]
RewriteCond %{QUERY_STRING} union([^a]*a)+ll([^s]*s)+elect [NC]
RewriteRule .* - [F]

## Referrer filtering for common media files. Replace with your own domain
name.
## This blocks most common fingerprinting attacks ;)
## Note: Change www\.example\.com with your own domain name, substituting the
## dots with \. i.e. use www\.example\.com for www.example.com
RewriteRule
^images/stories/([^/]+/)*([^/.]+\.)+(jp(e?g|2)?|png|gif|bmp|css|js|swf|ico)$
- [L]
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?example\.com [NC]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.(jp(e?g|2)?|png|gif|bmp|css|js|swf|ico)$ - [F]
## Disallow visual fingerprinting of Joomla! sites (module position dump)
## Initial idea by Brian Teeman and Ken Crowder, see:
## http://www.slideshare.net/brianteeman/hidden-joomla-secrets
## Improved by @nikosdion to work more efficiently and handle template
## and tmpl query parameters
RewriteCond %{QUERY_STRING} (^|&)tmpl=(component|system) [NC]
RewriteRule .* - [L]
RewriteCond %{QUERY_STRING} (^|&)t(p|emplate|mpl)= [NC]
RewriteRule .* - [F]

## Disallow access to htaccess.txt, configuration.php, configuration.php-dist


and php.ini
RewriteRule ^(htaccess\.txt|configuration\.php(-dist)?|php\.ini)$ - [F]

########## End - Advanced server protection - query strings, referrer and


config

########## Begin - Advanced server protection rules exceptions ####


##
## These are sample exceptions to the Advanced Server Protection 3.1
## rule set further down this file.
##
## Allow UddeIM CAPTCHA
RewriteRule ^components/com_uddeim/captcha15\.php$ - [L]
## Allow Phil Taylor's Turbo Gears
RewriteRule ^plugins/system/GoogleGears/gears-manifest\.php$ - [L]
## Allow JoomlaWorks AllVideos
RewriteRule ^plugins/content/jw_allvideos/includes/jw_allvideos_scripts\.php$
- [L]
## Allow Admin Tools Joomla! updater to run
RewriteRule ^administrator/components/com_admintools/restore\.php$ - [L]
## Allow Akeeba Backup Professional's integrated restoration script to run
RewriteRule ^administrator/components/com_akeeba/restore\.php$ - [L]
## Allow Akeeba Kickstart
RewriteRule ^kickstart\.php$ - [L]

# Add more rules to single PHP files here

## Allow Agora attachments, but not PHP files in that directory!


RewriteCond %{REQUEST_FILENAME} !(\.php)$
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^components/com_agora/img/members/ - [L]

# Add more rules for allowing full access (except PHP files) on more
directories here

## Uncomment to allow full access to the cache directory (strongly not


recommended!)
#RewriteRule ^cache/ - [L]
## Uncomment to allow full access to the tmp directory (strongly not
recommended!)
#RewriteRule ^tmp/ - [L]

# Add more full access rules here

########## End - Advanced server protection rules exceptions ####


########## Begin - Advanced server protection - paths and files
# Advanced server protection, version 3.2 - May 2011
# by Nicholas K. Dionysopoulos

## Back-end protection
## This also blocks fingerprinting attacks browsing for XML and INI files
RewriteRule ^administrator/?$ - [L]
RewriteRule ^administrator/index\.(php|html?)$ - [L]
RewriteRule ^administrator/index[23]\.php$ - [L]
RewriteRule
^administrator/(components|modules|templates|images|plugins)/([^/]+/)*([^/.]+
\.)+(jp(e?g|2)?|png|gif|bmp|css|js|swf|html?|mp(eg?|[34])|avi|wav|og[gv]|xlsx
?|docx?|pptx?|zip|rar|pdf|xps|txt|7z|svg|od[tsp]|flv|mov)$ - [L]
RewriteRule ^administrator/ - [F]

## Explicitly allow access only to XML-RPC's xmlrpc/index.php or plain


xmlrpc/ directory
RewriteRule ^xmlrpc/(index\.php)?$ - [L]
RewriteRule ^xmlrpc/ - [F]

## Disallow front-end access for certain Joomla! system directories


RewriteRule ^includes/js/ - [L]
RewriteRule ^(cache|includes|language|libraries|logs|tmp)/ - [F]

## Allow limited access for certain Joomla! system directories with client-
accessible content
RewriteRule
^(components|modules|plugins|templates)/([^/]+/)*([^/.]+\.)+(jp(e?g|2)?|png|g
if|bmp|css|js|swf|html?|mp(eg?|[34])|avi|wav|og[gv]|xlsx?|docx?|pptx?|zip|rar
|pdf|xps|txt|7z|svg|od[tsp]|flv|mov)$ - [L]
## Uncomment this line if you have extensions which require direct access to
their own
## custom index.php files. Note that this is UNSAFE and the developer should
be ashamed
## for being so lame, lazy and security unconscious.
# RewriteRule ^(components|modules|plugins|templates)/([^/]+/)*(index\.php)?$
- [L]
## Uncomment the following line if your template requires direct access to
PHP files
## inside its directory, e.g. GZip compressed copies of its CSS files
# RewriteRule ^templates/([^/]+/)*([^/.]+\.)+php$ - [L]
RewriteRule ^(components|modules|plugins|templates)/ - [F]

## Disallow access to rogue PHP files throughout the site, unless they are
explicitly allowed
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteCond %{REQUEST_FILENAME} !/index[23]?\.php$
## The next line is to explicitly allow the forum post assistant(fpa-
xx)script to run
RewriteCond %{REQUEST_FILENAME} !/fpa-[a-z]{2}\.php
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^([^/]+/)*([^/.]+\.)+php$ - [F]

########## End - Advanced server protection - paths and files

########## Begin - Google Apps redirection, by Komra.de


## Uncomment the following line to enable:
# RewriteRule ^mail http://mail.google.com/a/example.com [R=301,L]
## If the above doesn't work on your server, try this:
## RewriteRule ^mail http://mail.google.com/a/example.com [R,L]
########## End - Google Apps redirection

########## Begin - Custom redirects


#
# If you need to redirect some pages, place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
########## End - Custom redirects

########## Begin - Redirect (www.)olddomain.com to www.example.com


## Note: olddomain.com is your old domain name, you want to redirect FROM,
## whereas www.example.com is the new domain name you want to redirect TO.
## Change those names to reflect your current configuration. Remember, this
## small part of the file is supposed to be placed in www.olddomain.com!
## Note: Replace [R=301,L] with [R,L] if you get error 500.
## Uncomment the following lines to enable:
# RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com [NC]
# RewriteRule (.*) http://www.example.com/$1 [R=301,L]
## Note: The above section is only required if you are changing your domain
name.
########## End - Redirect (www.)olddomain.com to www.example.com

########## Begin - Force HTTPS for certain pages


# Force the page foobar.html to run in HTTPS mode, no matter what Joomla!
says.
# This is a sample redirection for foobar.html. Do note that you have to
change
# www.example.com to reflect your own domain. Remember to escape the dots
using
# \. in the left hand side of each rule. You need BOTH LINES PER URL for the
rule
# to work.
RewriteCond %{SERVER_PORT} !^443$
## Alternatively, comment the above line and uncomment the following line:
# RewriteCond %{HTTPS} ^off$ [NC]
RewriteRule ^foobar\.html$ https://www.example.com/foobar.html [R=301,L]
## NOTE: If you get an HTTP 500 error, please swap [R=301,L] with [R,L]
# Add more rules below this line as required
########## End - Force HTTPS for certain pages

########## Begin - Redirect index.php to /


## Note: Change example.com to reflect your own domain name
RewriteCond %{THE_REQUEST} !^POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteCond %{SERVER_PORT}>s ^(443>(s)|[0-9]+>s)$
RewriteRule ^index\.php$ http%2://www.example.com/$1 [R=301,L]
## If the above line throws a 500 error, change [R=301,L] to [R,L]
########## End - Redirect index.php to /

########## Begin - Redirect non-www to www


RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
## If the above throws an HTTP 500 error, swap [R=301,L] with [R,L]
########## End - Redirect non-www to www

########## Begin - Redirect www to non-www


## WARNING: Comment out the non-www to www rule if you choose to use this
# RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
# RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
## If the above throws an HTTP 500 error, swap [R=301,L] with [R,L]
########## End - Redirect non-www to www

########## Begin - Custom internal rewrites


#
# If you need to internally rewrite some specific URL requests,
# place that code here. Ensure those internal rewrites use the
# correct RewriteRule syntax without domain name and with [L] flag.
#
########## End - Custom internal rewrites

########## Begin - Joomla! core SEF Section


#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for the site root, or for an extensionless URL,
# or the requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI}
/component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw|ini|zip|json|file))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
########## End - Joomla! core SEF Section

########## Begin - Optimal default expiration time


## Note: this might cause problems and you might have to comment it out by
## placing a hash in front of this section's lines
<IfModule mod_expires.c>
# Enable expiration control
ExpiresActive On

# Default expiration: 1 hour after request


ExpiresDefault "now plus 1 hour"

# CSS and JS expiration: 1 week after request


ExpiresByType text/css "now plus 1 week"
ExpiresByType application/javascript "now plus 1 week"
ExpiresByType application/x-javascript "now plus 1 week"

# Image files expiration: 1 month after request


ExpiresByType image/bmp "now plus 1 month"
ExpiresByType image/gif "now plus 1 month"
ExpiresByType image/jpeg "now plus 1 month"
ExpiresByType image/jp2 "now plus 1 month"
ExpiresByType image/pipeg "now plus 1 month"
ExpiresByType image/png "now plus 1 month"
ExpiresByType image/svg+xml "now plus 1 month"
ExpiresByType image/tiff "now plus 1 month"
ExpiresByType image/vnd.microsoft.icon "now plus 1 month"
ExpiresByType image/x-icon "now plus 1 month"
ExpiresByType image/ico "now plus 1 month"
ExpiresByType image/icon "now plus 1 month"
ExpiresByType text/ico "now plus 1 month"
ExpiresByType application/ico "now plus 1 month"
ExpiresByType image/vnd.wap.wbmp "now plus 1 month"
ExpiresByType application/vnd.wap.wbxml "now plus 1 month"
ExpiresByType application/smil "now plus 1 month"

# Audio files expiration: 1 month after request


ExpiresByType audio/basic "now plus 1 month"
ExpiresByType audio/mid "now plus 1 month"
ExpiresByType audio/midi "now plus 1 month"
ExpiresByType audio/mpeg "now plus 1 month"
ExpiresByType audio/x-aiff "now plus 1 month"
ExpiresByType audio/x-mpegurl "now plus 1 month"
ExpiresByType audio/x-pn-realaudio "now plus 1 month"
ExpiresByType audio/x-wav "now plus 1 month"

# Movie files expiration: 1 month after request


ExpiresByType application/x-shockwave-flash "now plus 1 month"
ExpiresByType x-world/x-vrml "now plus 1 month"
ExpiresByType video/x-msvideo "now plus 1 month"
ExpiresByType video/mpeg "now plus 1 month"
ExpiresByType video/mp4 "now plus 1 month"
ExpiresByType video/quicktime "now plus 1 month"
ExpiresByType video/x-la-asf "now plus 1 month"
ExpiresByType video/x-ms-asf "now plus 1 month"
</IfModule>
########## End - Optimal expiration time

If not using the suggested master htaccess file, the following suggestions will need
RewriteEngine set to On, and will likely also need Options +FollowSymLinks too:

# mod_rewrite in use
RewriteEngine On
Options +FollowSymLinks

Other useful settings


ServerSignature Off
RewriteCond %{REQUEST_METHOD} ^(HEAD|TRACE|DELETE|TRACK) [NC,OR]
RewriteCond %{THE_REQUEST} (\\r|\\n|%0A|%0D) [NC,OR]

RewriteCond %{HTTP_REFERER} (<|>|’|%0A|%0D|%27|%3C|%3E|%00) [NC,OR]


RewriteCond %{HTTP_COOKIE} (<|>|’|%0A|%0D|%27|%3C|%3E|%00) [NC,OR]
RewriteCond %{REQUEST_URI} ^/(,|;|:|<|>|”>|”<|/|\\\.\.\\).{0,9999} [NC,OR]

RewriteCond %{HTTP_USER_AGENT} ^$ [OR]


RewriteCond %{HTTP_USER_AGENT} ^(java|curl|wget) [NC,OR]
RewriteCond %{HTTP_USER_AGENT}
(winhttp|HTTrack|clshttp|archiver|loader|email|harvest|extract|grab|miner)
[NC,OR]
RewriteCond %{HTTP_USER_AGENT} (libwww-perl|curl|wget|python|nikto|scan)
[NC,OR]
RewriteCond %{HTTP_USER_AGENT} (<|>|’|%0A|%0D|%27|%3C|%3E|%00) [NC,OR]

#Block mySQL injects


RewriteCond %{QUERY_STRING}
(;|<|>|’|”|\)|%0A|%0D|%22|%27|%3C|%3E|%00).*(/\*|union|select|insert|cast|set
|declare|drop|update|md5|benchmark) [NC,OR]

RewriteCond %{QUERY_STRING} \.\./\.\. [OR]

RewriteCond %{QUERY_STRING} (localhost|loopback|127\.0\.0\.1) [NC,OR]


RewriteCond %{QUERY_STRING} \.[a-z0-9] [NC,OR]
RewriteCond %{QUERY_STRING} (<|>|’|%0A|%0D|%27|%3C|%3E|%00) [NC]
# Note: The final RewriteCond must NOT use the [OR] flag.

# Return 403 Forbidden error.


RewriteRule .* index.php [F]

Block bad user agents


########## Block bad user agents
## The following list may include bots that no longer exist or are not a
problem
## for your site. The list will always be incomplete and it is therefore
wise to
## follow discussions on one of the many "security" mailing lists or on a
forum
## such as http://www.webmasterworld.com/search_engine_spiders/
## It is also unwise to rely on this list as your ONLY security mechanism.
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:craftbot@yahoo.com [OR]
RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR]
RewriteCond %{HTTP_USER_AGENT} ^Custo [OR]
RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR]
RewriteCond %{HTTP_USER_AGENT} ^Download\ Demon [OR]
RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR]
RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR]
RewriteCond %{HTTP_USER_AGENT} ^Express\ WebPictures [OR]
RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR]
RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR]
RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR]
RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR]
RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR]
RewriteCond %{HTTP_USER_AGENT} ^HMView [OR]
RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Image\ Stripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^Image\ Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} Indy\ Library [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR]
RewriteCond %{HTTP_USER_AGENT} ^Internet\ Ninja [OR]
RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR]
RewriteCond %{HTTP_USER_AGENT} ^JOC\ Web\ Spider [OR]
RewriteCond %{HTTP_USER_AGENT} ^larbin [OR]
RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mass\ Downloader [OR]
RewriteCond %{HTTP_USER_AGENT} ^MIDown\ tool [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mister\ PiX [OR]
RewriteCond %{HTTP_USER_AGENT} ^Navroad [OR]
RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Net\ Vampire [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline\ Explorer [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline\ Navigator [OR]
RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^Papa\ Foto [OR]
RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR]
RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR]
RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR]
RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR]
RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR]
RewriteCond %{HTTP_USER_AGENT} ^Teleport\ Pro [OR]
RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR]
RewriteCond %{HTTP_USER_AGENT} ^Web\ Image\ Collector [OR]
RewriteCond %{HTTP_USER_AGENT} ^Web\ Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebGo\ IS [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebReaper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website\ eXtractor [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website\ Quester [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Widow [OR]
RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
## Note: The final RewriteCond must NOT use the [OR] flag.

## Return 403 Forbidden error.


RewriteRule .* - [F]

Anda mungkin juga menyukai