Membuat alamat link URL menjadi cantik
Rewrite URL adalah salah satu dari tenik SEO.
Berikut contoh simple pembuatan URL cantik menggunakan .htaccess
simpan file pada root folder project Anda dengan nama .htaccess
1 2 3 4 5 6 |
RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.+) - [PT,L] RewriteRule ^(.*)$ index.php?do=$1 [QSA,L] |
lalu pada file index.php Anda, mainkan aturan URL-nya.
contoh isi file index.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
<?php $do = explode ("/", $_REQUEST['do']); $opsi = $do[0]; define('PUB_DIR', dirname (__FILE__) . '/'); switch($opsi) { case 'home': require_once (PUB_DIR . 'home.php'); break; case 'content': require_once (PUB_DIR . 'web_content.php'); break; case 'subcontent': require_once (PUB_DIR . 'web_content_sub.php'); break; case 'news': require_once (PUB_DIR . 'news.php'); break; case 'news-detail': require_once (PUB_DIR . 'news-detail.php'); break; case 'articles': require_once (PUB_DIR . 'articles.php'); break; case 'article-detail': require_once (PUB_DIR . 'article-detail.php'); break; case 'event': require_once (PUB_DIR . 'event.php'); break; case 'event-detail': require_once (PUB_DIR . 'event-detail.php'); break; case 'calendar': require_once (PUB_DIR . 'calendar.php'); break; case 'testimonial': require_once (PUB_DIR . 'testimonial.php'); break; case 'testimonial-sign': require_once (PUB_DIR . 'guestbook_sign.php'); break; case 'product': require_once (PUB_DIR . 'product.php'); break; case 'product_search': require_once (PUB_DIR . 'product_search.php'); break; case 'contact': require_once (PUB_DIR . 'contact_us.php'); break; case 'search': require_once (PUB_DIR . 'search.php'); break; case 'download': require_once (PUB_DIR . 'download.php'); break; case 'faq': require_once (PUB_DIR . 'faq.php'); break; case 'sitemap': require_once (PUB_DIR . 'sitemap.php'); break; default: require_once (PUB_DIR . 'home.php'); } |
Semoga membantu
thanks atas tip htaccess nya mas/mbak. mau coba2 ah
Misalkan kita tulis link url
1) http://test/halo/ atau
2) http://test/halo
bagaimana cara membuat jika user mengetikkan seperti point 2 diatas agas selalu terdirect ke link pada point 1. Tks.
@Suta,
Coba pakai ini di file .htacess:
Boss!! saya mo nanya, ini apabila saya ketik url
point 1;
http://alamatsitus.com/namasaya/ kemudian enter “muncul pesan dari apache server bahwasanya alamat tidak ditemukan – 404 not found – dan halaman situs pun hilang”.
point 2;
http://alamatsitus.com/namasaya/ kemudian enter “muncul pesan yang mungkin si admin web yang ngenulis – 404 not found – tanpa menghilangkan halaman situs.”
apa pesan diatas menggunakan fungsi .htaccess? apabila iya, bagaimana sintak / penulisannya. atas jawabannya saya ucapkan terimakasih 😀
@smadav, halo,.. Anda bisa gunakan code htacess seperti ini:
dan dapat di custome sesuai keinginan Anda.
Thank mas 😀
mau tanya mas, saya sudah buat 3 halaman
1.http://www.toserbavirtual.com/a/b/disini.php
2.http://www.toserbavirtual.com/a/b/disana.php
3.http://www.toserbavirtual.com/a/b/disitu.php
kasusnya :
bagaimana jika seseorang menginput langsung “http://www.toserbavirtual.com/a/b/” otomatis langsung redirect ke : “http://www.toserbavirtual.com/a/b/disini.php”
terima kasih sebelumnya, berjam-jam saya cari di google ga ketemu 😀
@toserbavirtual, halo… apakah a/b adalah folder dalam disk? atau semuanya di control oleh index.php seperti yg saya berikan contoh diatas?
jika a dan b tersebut adalah folder disk secara fisik ada di system www/htdocs/public_html Anda, silahkan dengan cara membuat file index.php di folder tersebut.
Lalu isikan kode redirect berikut:
Jika menggunakan sistem index.php seperti diatas, bagaimana contoh Anda memecahnya? apakah dengan $do[0] $do[1] dst? atau bagaimana?
500 internal error
knp tuh bang?
@ahmad,
lihat eror log pada webserver
biasanya bermasalah dengan real path, path server
fix-kan bagian yg error
http://www.nusansifor.com/2009/11/server-internal-error-500/
Dicoba saja, barangkali hostingannya perlu pakai:
RewriteBase /
Jadi htaccess nya:
kang Jawaad,
gimana kalo misalnya http://domain.com/index.php?menu=abc&merek=def
mau seperti http://domain.com/abc/def
dan kalo misalnya http://domain.com/index.php?id=ghi
mau seperti http://domain.com/abc/def/ghi.asp
Terimakasih ya… 🙂
@Arief,
bisa dicoba begini mas:
contoh http://localhost/lpmai/admin/user/insert.php
kalau dibuat http://localhost/lpmai/
bisa tidak ya kang?
Bisa dicoba seperti ini:
Tapi sebenernya tidak disarankan, karena ini artinya hanya untuk insert.php saja, mengapa tidak untuk link lainnya?
nanya gan gimana caranya http://saya.shop/test/client.php diganti menjadi http://saya.shop/test/home saya pake kode di atas hasilnya error terus