How to convert dynamic URLs to static using .htaccess

Web programming topics
Post Reply
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

How to convert dynamic URLs to static using .htaccess

Post by Neo » Sun Jan 24, 2010 4:35 am

Static URLs are said to improve search engine visibility, etc... When we have few parameters on the URL, this is possible through .htaccess.

Original URL
Ex: https://robot.lk/viewtopic.php?f=41&t=1149

Rewriting Friendly URL
Ex: https://robot.lk/41/1149

.htaccess Code

Code: Select all

//First Parameer
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ viewforum.php?f=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ viewforum.php?f=$1

//Second Parameter
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ viewforum.php?f=$1&t=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ viewforum.php?f=$1&t=$2
Post Reply

Return to “Web programming”