
Selama ini saya meng-install Joomla di dalam sebuah direktori (folder) bukan di root, misalkan folder tersebut bernama ‘cms’ (tanpa tanda kutip). Masalahnya, setiap kali pengunjung mengunjungi situs saya, membuka sebuah kategori di website saya (mis. tips), mereka akan melihat semua konten dalam kategori tips ada di http://www.joomla-di-subdirektori.com/cms/tips/judul-artikel. Saya ingin nama direktori ‘cms’ disembunyikan sehingga alamat yang muncul adalah http://www.joomla-di-subdirektori.com/tips/judul-artikel di browser mereka. Solusinya dengan menggunakan file .htaccess.
Setelah berhari-hari mencari solusi yang cocok di internet, saya menemukan bahwa file .htaccess menjadi jawaban atas pertanyaan saya ini. Masalahnya, dari sekian banyak solusi yang ditawarkan tidak ada yang bisa 100 persen langsung digunakan. Saya harus trial and error dulu sambil memadukan beberapa solusi menjadi sebuah solusi yang berfungsi dan cocok dengan kebutuhan saya (mudah-mudahan cocok juga dengan kebutuhan Anda).
Sebelum berurusan dengan kode-kode, ada baiknya kita ulas sedikit soal .htaccess ini. Sebab dengan satu file ini, kita bisa mengubah settingan default dari web server Apache. Sebagian besar hosting web di internet menggunakan Apache sebagai servernya sehingga bagi para pengelola web/webmaster perlu tahu cara memanfaatkan .htaccess.
Pada dasarnya, 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 sebaiknya di set 644 (rw-r-r). Hal tersebut dimaksudkan agar server dapat mengakses file .htaccess, tapi mencegah pengunjung mengakses file .htaccess dari browser mereka.
File .htaccess yang diletakkan dalam root direktori dapat digunakan untuk mengubah konfigurasi dari subdirektori-subdirektori yang ada di dalamnya. Tidak tertutup kemungkinan kita meletakkan file .htaccess tambahan dalam subdirektori untuk konfigurasi lebih spesifik terhadap subdirektori tersebut.
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. Notepad di Windows bisa digunakan untuk membuat file .htaccess. Dengan catatan, saat menyimpan file baru via notepad, pastikan ‘Save as type’ dipilih ‘All files (*.*) lalu beri nama .htaccess.
Contoh sederhana dari penggunakan file .htaccess adalah sebagai berikut. Biasanya, dengan meletakkan file ‘index.html’ dalam sebuah direktori, browser (atas perintah server) secara otomatis membuka file index.html tersebut. Namun dengan bantuan file .htaccess kita bisa memerintahkan server agar setiap kali browser mengakses direktori ‘belanja’ misalnya, file ‘beranda.html’ yang dibuka. Caranya cukup mudah dengan memasukkan kode berikut ke dalam file .htaccess:
DirectoryIndex beranda.html
Kembali ke topik permasalahan sebelumnya dimana saya ingin menyembunyikan ‘cms’ dari URL (front-end) dan me-redirect semua konten sehingga seolah-olah semua file Joomla ada di root bukan dalam folder ‘cms’. Saya juga ingin solusi dengan .htaccess ini berfungsi baik saat mengakses back-end Joomla (administrator), tidak ada masalah dengan komponen-komponen Joomla lainnya, dan ARTIO JoomSEF yang selama ini saya gunakan tetap berfungsi sebagaimana mestinya.
Setelah beberapa waktu menggunakan solusi .htaccess ini dan berfungsi sebagaimana mestinya, saya ingin membagikannya kepada Sobat UF yang menggunakan Joomla sebagai ‘mesin’ di situsnya. Berikut ini panduannya.
- File .htaccess bawaan Joomla tidak perlu dikutak-katik/dihapus. Biarkan saja ada di dalam direktori (folder) tempat Anda menaruh semua file Joomla. Dalam contoh ini, dalam folder ‘cms’. Berikut ini file .htaccess standar bawaan Joomla:
##
# @version $Id: htaccess.txt 10492 2008-07-02 06:38:28Z ircmaxell $
# @package Joomla
# @copyright Copyright (C) 2005 – 2008 Open Source Matters. All rights reserved.
# @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
# Joomla! is Free Software
##
#####################################################
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
#
# The line just below this section: ‘Options +FollowSymLinks’ may cause problems
# with some server configurations. It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file. If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url’s. If they work,
# it has been set by your server administrator and you do not need it set here.
#
#####################################################
## Can be commented out if causes errors, see notes above. (Saya non-aktifkan)
#Options +FollowSymLinks
#
# mod_rewrite in use
RewriteEngine On
########## 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!
#
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%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})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#
########## End – Rewrite rules to block out some common exploits
# Uncomment following line if your webserver’s URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root)
# RewriteBase /
########## Begin – Joomla! core SEF Section
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End – Joomla! core SEF Section
- Yang perlu kita lakukan adalah membuat duplikat (copy) .htaccess bawaan Joomla tersebut lalu menaruhnya di root. Biasanya dalam folder ‘www’ atau ‘public_html’ di server. Setelah itu masukkan kode-kode berikut di antara # RewriteBase dan ########## Begin – Joomla! core SEF Section. Ubah bagian yang saya bold warna merah dengan URL dan nama folder milik Anda:
# RewriteBase /
## The following section must come next immediately after the Rewrite Base command!
###BEGINNING OF SECTION###
#This masks the Joomla Subdir name in the URL and allows access to other subdirectories in the root
# Add trailing slash if path does not contain a period or end with a slash
##(after $1 in second line – you may need to test the need for this by trial and error).
RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule (.*) http://www.joomla-di-subdirektori.com/$1/ [R=301,L]
#sometimes they don’t always link to you in the way that you want them to.
# If somebody links to www.yoursite.com and somebody else links to yoursite.com,
#Google will assign a separate pagerank for each of those. Yes, it is stupid but it is true,
#by inserting the below example into your .htaccess file,
#it will solve the problem by redirecting anything linking to yoursite.com to www.yoursite.com,
#also redirecting the pagerank.
#
rewritecond %{http_host} ^joomla-di-subdirektori\.com [NC]
rewriteRule ^(.*) http://www.joomla-di-subdirektori.com/$1 [R=301,L,NC]
##Rewrites http://www.yoursite.com/subdir to http://www.yoursite.com/
##and it allows selected subdirectories to be also be accessed.
##For example, if you have document downloads in a subdir2 that are to be accessed directly
##or through a call from your Joomla code,
##you need to specify them in the second RewriteRule that follows.
##I suggest that at minimum you specify your Joomla subsirectory [i]subdir[i].
##Also do not terminate the list with |.
RewriteRule ^$ /cms/ [QSA,L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule !^(cms)(/.*)?$ /cms%{REQUEST_URI} [QSA,L]
###END OF SECTION###
########## Begin – Joomla! core SEF Section
- Kemudian, edit file configuration.php milik Joomla.
$live_site = ‘http://www.joomla-di-subdirektori.com’;
$sef = ‘1′
$sef_rewrite = ‘1′
$sef_suffix = ‘0′
Atau masuk ke Joomla backend.
Site –> Global Configuration –> Site –> SEO Settings

- Bersihkan cache yang disimpan Joomla dan atau ARTIO JoomSEF. Cara membersihkan cache Joomla: Masuk ke Joomla backend lalu pilih Tools –> Clean Cache –> Centang semua opsi –> Delete. Cara membersihkan cache ARTIO JoomSEF: Components –> ARTIO JoomSEF –> Clean Cache.
- Bersihkan browsing history di browser (bila perlu, setelah itu restart komputer).
- Silakan buka alamat website Anda via browser. Dalam contoh ini, http://www.joomla-di-subdirektori.com. Coba browsing konten-konten yang ada di dalam situs tersebut sambil memperhatikan apakah ‘cms’ (contoh dalam tulisan ini) masih muncul di URL. Kalau sudah ‘disembunyikan’ berarti Anda sukses mempraktikkan panduan ini. Kalau belum, coba telusuri lagi panduan ini, periksa apakah ada panduan/kode yang terlewat. Anda juga perlu memastikan apakah ada komponen Joomla yang menjadi tidak bisa dibuka (404 error page). Contohnya, kalau Anda menggunakan Community Builder (CB), solusi .htaccess ini kurang cocok untuk Anda karena membuat Anda tidak bisa login ke CB.
Untuk informasi lebih lanjut seputar .htaccess di Joomla, silakan buka:
Popularity: 1% [?]
Tulisan Terkait