Sunday, 12 May 2013
Facebook StumbleUpon Twitter Google+ Pin It

Pretty URLs with .htaccess Rewriting Tips

Pretty URLs always helps you to boost up search engine page ranking. In this post I want to explain about URLs rewriting techniques using .htaccess file. Friendly URLs looks neat on the browser address bar. 

Pretty URLs with .htaccess Rewriting Tips.

Long days back I had discussed about .htaccess basic rewriting tips Eg. First parameter to take a look the following link.

This time I'm talking about rewriting second parameter URLs using .htaccess file.

Original URL.

Rewriting Friendly URL.

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

//Second Parameter
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ users.php?user=$1&page=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ users.php?user=$1&page=$2

Twitter like Pretty URLs

.htaccess Code
Just rewriting first parameter.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?key=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?key=$1

Contains simple PHP code.


include('home.php'); // Home page
else if($key=='login')
include('login.php'); // Login page
else if($key=='terms')
include('terms.php'); // Terms page
include('users.php'); // Users Gateway
Parthiv Patel
Bhaishri Info Solution
Sr. PHP Developer
Limdi Chowk, AT PO. Nar, Di. Anand
Nar, Gujarat
DOB: 12/24/1986

No comments: