Security:htaccess: Difference between revisions

Line 33: Line 33:


==Generate Apache Error documents for different error codes==
==Generate Apache Error documents for different error codes==
Using some simple lines, we can fix the error document that run on different error codes generated by the server when user/client requests a page not available on the website like most of us would have seen the ‘404 Page not found’ page in their web browser. .htaccess’ files specify what action to take in case of such error conditions.
Menggunakan beberapa baris sederhana, kita dapat memperbaiki dokumen kesalahan yang berjalan pada kode kesalahan berbeda yang dihasilkan oleh server ketika pengguna/klien meminta halaman yang tidak tersedia di situs web seperti kebanyakan dari kita akan melihat halaman '404 Halaman tidak ditemukan' di halaman mereka peramban web. File <code>.htaccess</code> menentukan tindakan apa yang harus diambil jika terjadi kondisi kesalahan seperti itu.


To do this, the following lines are needed to be added to the ‘.htaccess’ files:
Untuk melakukan ini, baris berikut perlu ditambahkan ke file <code>.htaccess</code>:


  ErrorDocument <error-code> <path-of-document/string-representing-html-file-content>
  ErrorDocument <error-code> <path-of-document/string-representing-html-file-content>


‘ErrorDocument’ is a keyword, error-code can be any of 401, 403, 404, 500 or any valid error representing code and lastly, ‘path-of-document’ represents the path on the local machine (in case you are using your own local server) or on the server (in case you are using any other’s server to host your website).
<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
  ErrorDocument 404 /error-docs/error-404.html


The above line sets the document ‘error-404.html’ placed in error-docs folder to be displayed in case the 404 error is reported by the server for any invalid request for a page by the client.
Baris di atas mengatur dokumen <code>error-404.html</code> yang ditempatkan di folder error-docs 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>
  <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>
The above representation is also correct which places the string representing a usual html file.


==Setting/Unsetting Apache server environment variables==
==Setting/Unsetting Apache server environment variables==