Home » » Url Rewriting with .htaccess file

Url Rewriting with .htaccess file

Written By Unknown on Senin, 13 Juni 2011 | 03.53

Now, Its time to clean up our url. It is very important to have keywords in the url so that search engines can tackle them easily. Further Rewriting urls makes it more readable and it looks very clean.

We can rewrite our urls using .htaccess file. So let us start with

What is .htaccess file?

It is a common file used by several web servers to control configuration for a directory. Also known as hypertextaccess. It is an extremely sensitive file.

A missing semi colon, incorrect letter or an extra backslash can mess everything up. So, be careful while working with this file.

To achieve this we have to follow these steps :
 
1. Create a .htaccess file. Save this file in root directory.
2. Enable the RewriteEngine with this code

        RewriteEngine on
 
3. Now define RewriteRule for the configuration

       RewriteRule ^product-([^/]+)\.html$ product.php?category=$1

Syntax : RewriteRule INPUTURL OUTPUTURL [FLAGS]

 RewriteEngine on
RewriteRule ^product-([^/]+).\html$ product.php?category=$1


Above code will result following url -

Original Url    : http://example.com/product.php?category=car
After Rewriting : http://example.com/product-car.html

We can also make our urls look like directories as follows.
 
 RewriteEngine on
RewriteRule ^product/([^/]+).\html$ product.php?category=$1


Wait... One thing to note : Always use absolute paths for your links while dealing with directory type url rewriting.
Share this article :

Posting Komentar

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger