Skip to content

emka.web.id

menulis pengetahuan – merekam peradaban

Menu
  • Home
  • Tutorial
  • Search
Menu

How to Create SEO Friendly URL’s Using Mod Rewrite and PHP

Posted on March 29, 2013

Let’s look at a example of a URL which does not attract much Search Engine Love.

http://www.yoursite.com/product.php?productid=2&categoryid=3. It is hard even for a human to tell what the product is by looking at this URL. With the trick we will use the final URL can look something like this http://www.yoursite.com/product/13/3/2-GB-MP3-player.html.

Now if someone looks at this link they can easily know that the product is a 2 GB MP3 player. Now if you want hire a professional SEO to do the changes it may cost you quite a lot, with a little bit of PHP knowledge and using some simple URL rewriting using Apache Mod Rewrite you can achieve this for free.

I term this simple SEO rule as What to look for and Where to go. We’ll learn more about these terms as we get ahead with the tutorial.

Steps to Rewrite your URLs

Ok now that we have seen what Mod Rewrite actually does we will start on learning how to actually rewrite you URL.The first step you will need to undertake is create a .htaccess file and place it in the root directory of your website. Once you have created the file using a text editor edit it and add the following lines;

RewriteEngine on
RewriteRule ^article/([0-9]+)/([0-9]+)/(.*?).html$ /article.php?articleid=$1&categoryid=$2

 

Lets take a look at the two lines individually.

RewriteEngine on

This line tells the web server that we will be rewriting the URL’s otherwise it may start throwing 404 errors, this line is very important before you can start creating the rewrite rules. Now lets look at the second line which is the most crucial one in actually redirecting your URLs.

With this particular line we are creating a rule telling the web server that when it encounters a URL that matches the rule it should do what we have defined. Lets decipher the rule part by part. We are using a few Regex patterns which can be easily learnt through regex online tutorials.

RewriteRule ^article/([0-9]+)/([0-9]+)/(.*?).html$ /article.php?articleid=$1&categoryid=$2

In the above line RewriteRule (a rule to rewrite the URL for the web server Apache) tells the web server that this a rule that it should follow for URL rewriting. Further the rule is divided into two parts for simplicity lets call the first part “what to look for” and the second part “where to go”. So in the above line we are telling the web server what to look for and if it finds it where it should go.

The text forms the pattern of what to look for “^article/([0-9]+)/([0-9]+)/(.*?).html$”. The what to look for pattern should always end with a dollar($) sign. Lets compare the pattern with the URL we are aiming to create which is http://www.yoursite.com/product/13/3/2-GB-MP3-player.html. Lets divide the pattern into different parts and compare it with our URL.

  • The first character of the pattern the exponential sign “^” signifies the start of an URL in this casehttp://www.yoursite.com.
  • The next part article/ relates to the first directory in the URL which ends with a slash “/”.
  • Now the next section you will see something like this ([0-9]+) which a regular expression telling the web server that it can encounter any number between 0 and 9 after article/, the + sign signifies that the number can occur 1 or more times. For example your article id may be either 1, 20, 567, 2005 etc.
  • After that comes another ([0-9]+) which signifies the category id again your category id may be a single number or anything else.
  • After that we are using (.*?).html which is a wildcard saying after the last / we may have anything with any number of characters or numbers ending with a .html extension.
  • The $ lines tells the web server that this is the end of the pattern.

In the example we used ([0-9]+) but say your category id cannot be more than 100 then instead of using the + symbol you can tell the web server that there will be only a double digit number using [0-9][0-9]. In that case the rule would be changed as such

RewriteRule ^article/([0-9]+)/([0-9][0-9])/(.*?).html$ /article.php?articleid=$1&categoryid=$2

In the above example we looked at some not so simple regular expressions that can let the web server know that we are following a certain pattern for a URL that needs to be redirected. Though the above example looks tough, it’s not tough at all, once you get to know how to use the regular expressions.

Rewriting URL’s require you to use regular expressions and without knowing this you will have to pay the SEO guys a huge amount.

via Techie-Buzz

Terbaru

  • Apa Itu Pengertian Penonaktifan SPayLater? Ini Durasi Blokir Akibat Telat Bayar
  • Apa Itu Rasio Gambar Ukuran 1:1 di Canva? Ini Pengertian dan Cara Buatnya
  • Pengiriman Shopee Express Hemat itu Berapa Lama? Ini Pengertian dan Estimasi Sampainya
  • Android 2025: Aplikasi Baru dan Smartphone Impian yang Akan Datang!
  • Apa Itu Google AI Pro Ultra? Ini Pengertian dan Penjelasan Lengkapnya
  • Apa Itu Error Gagal Kirim Nilai RDM 3.1? Ini Pengertian dan Solusi Mengatasinya
  • Facebook Mulai Batasi Link Eksternal Cuma 2 Sebulan! Ini Trik Mengatasinya
  • Cara Nonton Tensura Season 4! Bakal Tayang April 2026 dengan Format 5 Cour
  • Belum Tahu? Inilah Trik Supaya Live TikTok Kalian Aman dan Banjir Cuan
  • Pixel 8 Dapatkan Mode Panorama Baru! Hasil Foto Lebih Luas & Lebih Kreatif
  • Apa Itu AppLocker? Ini Pengertian dan Cara Mengamankan Windows 11 Kalian dari Skrip Jahat
  • Cara Membuat Riwayat Copilot Kamu Tetap Bersih dan Rapi!
  • Game & Aplikasi Android Terbaik Saat Diskon Liburan Natal! Jangan Ketinggalan!
  • Apa Itu Game Prison Escape Journey? Ini Pengertian dan Cara Mainnya untuk Pemula
  • “Listrik Gratis” dari Solar Panel Cuma Mitos?! Ini Sisi Gelap PLTS
  • Samsung Galaxy Z-Fold: Uji Jatuh Bebas yang Mengguncang Keandalan Lipatannya
  • Google One 2026: Apa yang Akan Jadi Fitur Utama dan Harga yang Diharapkan?
  • Apa Itu Error 0x800704f8? Ini Pengertian dan Cara Mengatasinya
  • Android Akhirnya Dapat GPS Darurat di India! Setelah Hampir 10 Tahun
  • Apa Itu GetContact Premium? Ini Pengertian dan Cara Daftarnya
  • Android Maze Figure: Koleksi Baru Google yang Bikin Penggemar Bergairah!
  • Google Update Besar-besaran Desember 2025: Apa yang Akan Memengaruhi Pengalaman Anda?
  • Masih Pusing Hitung Gaji Manual? Waktunya Pakai Aplikasi HR
  • Apa Itu Dustruco? Ini Pengertian dan Cara Pasangnya di HP Kalian
  • Apa Itu Aplikasi Dooie Live? Ini Pengertian dan Cara Pakai Aplikasinya untuk Cari Jodoh
  • Apa Itu Battle Emote Jefri Nichol dan Om Telolet Om di MLBB? Ini Penjelasannya
  • Apa itu Game Luna Mobile dan Bagaimana Cara Menangnya?
  • Apa Itu Kompensasi Sistem Trail Mobile Legends? Ini Penjelasan dan Cara Klaim Hadiahnya
  • Apa Itu Update Google Pixel 2 Desember 2025? Ini Penjelasannya!
  • Ini Cara Reset Desil di Aplikasi Cek Bansos Biar Valid (Update Januari 2026)
  • Apa itu Cosmic Desktop: Pengertian dan Cara Pasangnya di Ubuntu 26.04?
  • Apa Itu Auvidea X242? Pengertian Carrier Board Jetson T5000 dengan Dual 10Gbe
  • Elementary OS 8.1 Resmi Rilis: Kini Pakai Wayland Secara Standar!
  • Apa Itu Raspberry Pi Imager? Pengertian dan Pembaruan Versi 2.0.3 yang Wajib Kalian Tahu
  • Performa Maksimal! Ini Cara Manual Update Ubuntu ke Linux Kernel 6.18 LTS
  • Inilah Cara Membuat AI Agent Cerdas dan Memantaunya Menggunakan LangGraph dan LangSmith
  • Ini Alasan China Akan Menang di Dunia AI
  • Apa Itu AI Gateway? Ini Definisi Tulang Punggung Infrastruktur AI Modern
  • Apa Itu Google AI Pro Ultra? Pengertian dan Bedah Fitur Terbarunya
  • Apa Itu FARA 7B? Ini Pengertian dan Cara Menjalankannya di Windows 11
  • Apa Itu Distribusi Malware Via YouTube? Ini Pengertian dan Bahayanya Buat Kalian
  • Apa Itu Undang-Undang NDAA? Ini Pengertian dan Dampaknya Bagi Cyber Command Amerika Serikat
  • Tagihan AWS Sekarang Bisa Dibayar Pakai BNB via BPN, Ini Caranya!
  • Video Botol Teh Pucuk 1 Menit 50 Detik yang Viral di TikTok! Hati-Hati Kejahatan Siber
  • Apa Itu Kerentanan WatchGuard CVE-2024-36193? Ini Penjelasannya
Beli Pemotong Rumput dengan Baterai IRONHOOF 588V Mesin Potong Rumput 88V disini https://s.shopee.co.id/70DBGTHtuJ
Beli Morning Star Kursi Gaming/Kantor disini: https://s.shopee.co.id/805iTUOPRV

©2025 emka.web.id | Design: Newspaperly WordPress Theme