0

Iklan Tengah Artikel 1

Home  ›  coding  ›  hosting  ›  Php  ›  web development  ›  website

Panduan pengguna .htaccess



htaccess adalah file konfigurasi di hosting web yang berjalan di website untuk mengatur beberapa konfigurasi Apache Web Server. File .htaccess dapat digunakan untuk mengubah konfigurasi seperti mengaktifkan dan menonaktifkan fungsionalitas yang berjalan, melakukan redirect, mengatur ulang URL, memproteksi direktori menggunakan password, proteksi hotlink, memblokir IP tertentu, mengganti zona waktu, dan masih banyak yang lainnya.

Perintah - perintah pada .htaccess :
# = untuk membuat komentar

# Allow .htaccess files their full powerAllowOverride All = mengaktifkan seluruh konfigurasi htaccess

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php //menyembunyikan RewriteEngine on RewriteRule ^(.*)\.html$ $1.php //merubah = menyembunyikannya dan mengubah ekstensi file. Contoh index.php jadi index.html

RewriteEngine On RewriteCond %{HTTP_HOST} ^www.riky.com RewriteRule (.*) http://riky.com/$1 [R=301,L] = redirect www ke non-www 

RewriteEngine On RewriteRule ^([a-zA-Z0-9_-]+)$ barang.php?id=$1 RewriteRule ^([a-zA-Z0-9_-]+)/$ barang.php?id=$1 = Menghilangkan url index.php contoh : http://example.com/barang.php?id=televisi menjadi http://example.com/televisi

# menghapus slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/$ $1 [R=301,L] = Menghapus akhiran slash ( / )

# menambahkan slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301] = menambah ( / ) slash di belakang url

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://domain.com/$1 [R,L] = Redirect HTTP ke HTTPS

# Setup browser caching <IfModule mod_expires.c> ExpiresActive On ExpiresByType image/jpg "access 1 year" ExpiresByType image/jpeg "access 1 year" ExpiresByType image/gif "access 1 year" ExpiresByType image/png "access 1 year" ExpiresByType text/css "access 1 month" ExpiresByType application/pdf "access 1 month" ExpiresByType text/x-javascript "access 1 month" ExpiresByType application/x-shockwave-flash "access 1 month" ExpiresByType image/x-icon "access 1 year" ExpiresDefault "access 2 days" </IfModule> = Mengaktifkan Browser Caching


# compress text, html, javascript, css, xml <IfModule mod_deflate.c> # Compress HTML, CSS, JavaScript, Text, XML and fonts AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/vnd.ms-fontobject AddOutputFilterByType DEFLATE application/x-font AddOutputFilterByType DEFLATE application/x-font-opentype AddOutputFilterByType DEFLATE application/x-font-otf AddOutputFilterByType DEFLATE application/x-font-truetype AddOutputFilterByType DEFLATE application/x-font-ttf AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE font/opentype AddOutputFilterByType DEFLATE font/otf AddOutputFilterByType DEFLATE font/ttf AddOutputFilterByType DEFLATE image/svg+xml AddOutputFilterByType DEFLATE image/x-icon AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/xml </IfModule> = Mengaktifkan gzip compression

# Prevent image hotlinking script. Replace last URL with any image link you want. RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?yourwebsite.com [NC] RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?yourotherwebsite.com [NC] RewriteRule .(jpg|jpeg|png|gif)$ https://i.ibb.co/bLdrrB8/plagiat.jpg [NC,R,L] = Mencegah Image Hotlink

# Deny access to wp-config.php file <files wp-config.php> order allow,deny deny from all </files> 

# Deny access to all .htaccess files <files ~ "^.*.([Hh][Tt][Aa])"> order allow,deny deny from all satisfy all </files> = Memproteksi wp-config.php dan .htaccess dari Siapapun

# Limit logins and admin by IP <Limit GET POST PUT> order deny,allow deny from all allow from 302.143.54.102 allow from IP_ADDRESS_2 </Limit> = Hanya Mengijinkan IP Tertentu untuk Mengakses wp-admin

# Block wp-includes folder and files <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^wp-admin/includes/ - [F,L] RewriteRule !^wp-includes/ - [S=3] RewriteRule ^wp-includes/[^/]+.php$ - [F,L] RewriteRule ^wp-includes/js/tinymce/langs/.+.php - [F,L] RewriteRule ^wp-includes/theme-compat/ - [F,L] </IfModule>
= Memblokir Seluruh Akses ke wp-includes

# Disable access to all file types except the following Order deny,allow Deny from all <Files ~ ".(xml|css|js|jpe?g|png|gif|pdf|docx|rtf|odf|zip|rar)$"> Allow from all </Files> = Hanya Mengijinkan Akses File Tertentu di Directory

Order Deny, Allow allow from all deny from 192.168.1.1 = Memblokir Alamat IP Tertentu

Order Deny, Allow allow from all deny from .namadomain.com = memblokir berdasarkan website

# Redirect dari HTTPS ke HTTP RewriteEngine On RewriteCond %{SERVER_PORT} 443 RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] = redirect dari https ke http

# Redirect seluruh website ke website lain RewriteCond %{HTTP_HOST} ^domainlama.com [NC,OR] RewriteCond %{HTTP_HOST} ^www.domainlama.com [NC] RewriteRule ^(.*)$ http://domainbaru.com/$1 [L,R=301,NC] = Redirect seluruh website ke website lain

# Redirect URL tertentu ke URL lain berbeda website Redirect 301 /urllama http://domainbaru.com/urlbaru = Redirect URL tertentu ke URL lain berbeda website





Posting Komentar
Theme
Share
Additional JS