Working on FIW.ME!

We are currently working on fiw.me a next generation URL shortener!

[How to] Hide “.php” file extension and beautify your URLs using .htaccess mod rewrite rule

Everybody likes SEO friendly and user friendly URLs, to customize the URLs you have to configure your Apache server and

Please remember, mod_rewrite should be enabled in Apache configuration in order to make this work. URL remapping should be done carefully, if any wrong changes are done then, whole website may stop working.

First, Lets see how can we redirect simple URLs like

From http://www.example.com/something.html to http://www.example.com/path/something.html

lets break it down,

This code “RewriteEngine On” above enables the rewrite_mod , so we can write redirect the pages.

The above line says the server that, when someone tries to reach “something.html” on local server, then take them to the new place “http://www.example/path/something.html

this symbol is used to tell to start matching the url
this symbol is used to tell to stop matching

So anything you write between and $ will be considered as pattern to be matched.

Now, Lets make Dynamic URL SEO Friendly

 you can make http://www.example.com/pages.php?id=1&no=5 look like http://www.example.com/pages/1/5/

by saving this in htaccess file

here as you can see I have used (.*) , this will preserve whatever is present in it and then it can be used again in future. 

( ) is used to preserve anything for future use and  (dot) is used to match any single character. is used to match the previous character for one or more times.

So anything typed where (.*) is present can be accessed by using $1 $2 so on.

Hide .php extension with .html

You can hide .php extension with .html and make it more SEO friendly, here is how to do it.

Write,

 This code here will redirect anything you type after domain, http://example.com/test to http://example.com/test.php

The code above works as condition, this condition first checks if the file already exists.

Above condition checks if the directory exists in that name.

If both conditions are false, then the code below executes.

this code redirects to its .php extension, like http://fiw.me/index to  http://fiw.me/index.php

(will be updated soon, keep reading)