• 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. Take a look at live demo

    Pretty URLs with .htaccess Rewriting Tips.

    Download Script     Live Demo

    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
    }
    ?>
  • You might also like

    No comments:

    Post a Comment

    Good day precious one, We love you more than anything.

Powered by Blogger.