Security:htaccess: Difference between revisions

No edit summary
No edit summary
Line 2: Line 2:
Opsi <code>mod_rewrite</code> memungkinkan Anda untuk menggunakan pengalihan dan menyembunyikan URL Anda yang sebenarnya dengan mengarahkan ke beberapa URL lain. Opsi ini terbukti sangat berguna sehingga Anda dapat mengganti URL yang panjang dan panjang menjadi yang pendek dan mudah diingat.
Opsi <code>mod_rewrite</code> memungkinkan Anda untuk menggunakan pengalihan dan menyembunyikan URL Anda yang sebenarnya dengan mengarahkan ke beberapa URL lain. Opsi ini terbukti sangat berguna sehingga Anda dapat mengganti URL yang panjang dan panjang menjadi yang pendek dan mudah diingat.


Untuk mengizinkan <code>mod_rewrite</code>, praktikkan saja untuk menambahkan baris berikut sebagai baris pertama file <code>.htaccess</code> Anda.<syntaxhighlight lang="apache">
Untuk mengizinkan <code>mod_rewrite</code>, praktikkan saja untuk menambahkan baris berikut sebagai baris pertama file <code>.htaccess</code> Anda.
 
<syntaxhighlight lang="apache">
Options +FollowSymLinks
Options +FollowSymLinks
</syntaxhighlight>Opsi ini memungkinkan Anda untuk mengikuti tautan simbolik dan dengan demikian mengaktifkan opsi <code>mod_rewrite</code> di situs web. Mengganti URL dengan yang pendek dan renyah disajikan nanti.
</syntaxhighlight>
 
Opsi ini memungkinkan Anda untuk mengikuti tautan simbolik dan dengan demikian mengaktifkan opsi <code>mod_rewrite</code> di situs web. Mengganti URL dengan yang pendek dan renyah disajikan nanti.


==How to Allow or Deny Access to Websites==
==How to Allow or Deny Access to Websites==
Line 14: Line 18:
Deny from All
Deny from All
Allow from 192.168.3.1
Allow from 192.168.3.1
</syntaxhighlight>Atau<syntaxhighlight lang="apache" line="1">
</syntaxhighlight>
 
Atau
 
<syntaxhighlight lang="apache" line="1">
Order Allow, Deny
Order Allow, Deny
Allow from 192.168.3.1
Allow from 192.168.3.1
</syntaxhighlight>Kata kunci pesanan di sini menentukan urutan pemrosesan izinkan, tolak akses. Untuk pernyataan 'Pesan' di atas, pernyataan Izinkan akan diproses terlebih dahulu dan kemudian pernyataan penolakan akan diproses.
</syntaxhighlight>
 
Kata kunci pesanan di sini menentukan urutan pemrosesan izinkan, tolak akses. Untuk pernyataan 'Pesan' di atas, pernyataan Izinkan akan diproses terlebih dahulu dan kemudian pernyataan penolakan akan diproses.


===Denying access to only one IP Address===
===Denying access to only one IP Address===
Baris di bawah ini menyediakan sarana untuk memungkinkan akses situs web ke semua pengguna yang menerima satu dengan Alamat IP: 192.168.3.1.<syntaxhighlight lang="apache" line="1">
Baris di bawah ini menyediakan sarana untuk memungkinkan akses situs web ke semua pengguna yang menerima satu dengan Alamat IP: 192.168.3.1.
 
<syntaxhighlight lang="apache" line="1">
Order Allow, Deny
Order Allow, Deny
Deny from 192.168.3.1
Deny from 192.168.3.1
Allow from All
Allow from All
</syntaxhighlight>Atau<syntaxhighlight lang="apache" line="1">
</syntaxhighlight>
 
Atau
 
<syntaxhighlight lang="apache" line="1">
Order Deny, Allow
Order Deny, Allow
Deny from 192.168.3.1
Deny from 192.168.3.1
Line 34: Line 50:
Untuk melakukan ini, baris berikut perlu ditambahkan ke file <code>.htaccess</code>:
Untuk melakukan ini, baris berikut perlu ditambahkan ke file <code>.htaccess</code>:


ErrorDocument <error-code> <path-of-document/string-representing-html-file-content>
<syntaxhighlight lang="shell">
ErrorDocument <error-code> <path-of-document/string-representing-html-file-content>
</syntaxhighlight>


<code>ErrorDocument</code> adalah kata kunci, kode kesalahan dapat berupa 401, 403, 404, 500 atau kesalahan valid yang mewakili kode dan terakhir, <code>path-of-document</code> mewakili jalur pada mesin lokal (jika Anda menggunakan server lokal Anda sendiri) atau di server (jika Anda menggunakan server lain untuk meng-host situs web Anda).
<code>ErrorDocument</code> adalah kata kunci, kode kesalahan dapat berupa 401, 403, 404, 500 atau kesalahan valid yang mewakili kode dan terakhir, <code>path-of-document</code> mewakili jalur pada mesin lokal (jika Anda menggunakan server lokal Anda sendiri) atau di server (jika Anda menggunakan server lain untuk meng-host situs web Anda).


'''Example:'''
'''Example:'''
ErrorDocument 404 /error-docs/error-404.html
<syntaxhighlight lang="shell">
ErrorDocument 404 /error-docs/error-404.html
</syntaxhighlight>


Baris di atas mengatur dokumen <code>error-404.html</code> yang ditempatkan di folder <code>error-docs</code> untuk ditampilkan jika kesalahan 404 dilaporkan oleh server untuk permintaan halaman yang tidak valid oleh klien.
Baris di atas mengatur dokumen <code>error-404.html</code> yang ditempatkan di folder <code>error-docs</code> untuk ditampilkan jika kesalahan 404 dilaporkan oleh server untuk permintaan halaman yang tidak valid oleh klien.


<nowiki>errorDocument 404 "<html><head><title>404 Page not found</title></head><body><p>The page you request is not present. Check the URL you have typed</p></body></html>"</nowiki>
<syntaxhighlight lang="shell">
errorDocument 404 "<html><head><title>404 Page not found</title></head><body><p>The page you request is not present. Check the URL you have typed</p></body></html>"
</syntaxhighlight>


==Setting/Unsetting Apache server environment variables==
==Setting/Unsetting Apache server environment variables==
Line 49: Line 71:


===Setting the Environment variables===
===Setting the Environment variables===
SetEnv OWNER “Gunjit Khera”
 
<syntaxhighlight lang="apache">
SetEnv OWNER “Gunjit Khera”
</syntaxhighlight>


===Unsetting the Environment variables===
===Unsetting the Environment variables===
UnsetEnv OWNER
 
<syntaxhighlight lang="apache">
UnsetEnv OWNER
</syntaxhighlight>


==Defining different MIME types for files==
==Defining different MIME types for files==
MIME (Multipurpose Internet Multimedia Extensions) are the types that are recognized by the browser by default when running any web page. You can define MIME types for your website in .htaccess files, so that different types of files as defined by you can be recognized and run by the server.
MIME (Multipurpose Internet Multimedia Extensions) are the types that are recognized by the browser by default when running any web page. You can define MIME types for your website in .htaccess files, so that different types of files as defined by you can be recognized and run by the server.


<IfModule mod_mime.c>
<syntaxhighlight lang="apache">
    AddType application/javascript js
<IfModule mod_mime.c>
    AddType application/x-font-ttf ttf ttc
    AddType application/javascript js
</IfModule>
    AddType application/x-font-ttf ttf ttc
</IfModule>
</syntaxhighlight>


Here, mod_mime.c is the module for controlling definitions of different MIME types and if you have this module installed on your system then you can use this module to define different MIME types for different extensions used in your website so that server can understand them.
Here, mod_mime.c is the module for controlling definitions of different MIME types and if you have this module installed on your system then you can use this module to define different MIME types for different extensions used in your website so that server can understand them.
Line 67: Line 97:
.htaccess files allow you the feature to control the amount of data being uploaded or downloaded by a particular client from your website. For this you just need to append the following lines to your .htaccess file:
.htaccess files allow you the feature to control the amount of data being uploaded or downloaded by a particular client from your website. For this you just need to append the following lines to your .htaccess file:


php_value upload_max_filesize 20M
<syntaxhighlight lang="apache">
php_value post_max_size 20M
php_value upload_max_filesize 20M
php_value max_execution_time 200
php_value post_max_size 20M
php_value max_input_time 200
php_value max_execution_time 200
php_value max_input_time 200
</syntaxhighlight>


The above lines set maximum upload size, maximum size of data being posted, maximum execution time i.e. the maximum time the a user is allowed to execute a website on his local machine, maximum time constrain within on the input time.
The above lines set maximum upload size, maximum size of data being posted, maximum execution time i.e. the maximum time the a user is allowed to execute a website on his local machine, maximum time constrain within on the input time.