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 Domain.com/users?id=9lessons to Domain.com/9lessons take a look the following link.

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


Original URL.
Eg. http://flickr.com/users.php?id=username&page=2

Rewriting Friendly URL.
Eg. http://flickr.com/username/2

.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

index.php
Contains simple PHP code.
<?php

$key=$_GET['key'];

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

No comments: