Friday 12 July 2013

Tutorial : How to Hide PHP extension in URL using .htaccess

Hello Friend,
Today, I came with a new topic URL rewriting using .htacess file …
As we know that URL Rewriting is one of the good techniques followed in Search Engine Optimization. If your URL is not proper if your webpage URL? includes junk or encrypted code than You must use URL rewriting technique So that your URL could be Search Engine Friendly and easy to remember for users…

What is the benefits of rewriting URL?


There are some benefits of rewrite the URL :
  • Making your webpage URLs cleaner and easier to remember for visitors
  • Make dynamic pages appear static for SEO purpose
  • Security purpose – visitors cannot tell as easily that you are using PHP.
  • Static URL looks pretty or friendlier.

How to rewrite URL?

 
First of you need to open a notepad file and save it .htaccess and place it in to root directory of your website. where you hosted your website.
Bow just look at below examples of the codes you can copy and paste the code directly to your .htaccess file according to your need.

Below are the some different way to rewrite your webpage URL with different types of URL …
 
1. Rewriting the www.yoursite.com/test.php to www.yoursite.com/test.html :
Add the following code into the .htaccess file.
 
After placing the code, when the URL like http://yoursite.com/test.htm is called in address bar it calls the file test.php.
 
2. Rewriting? www.yoursite.com/product.php?id=12 towww.yoursite.com/product/webcam/12.html

You can smartly place the keyword in the url using this technique,. Like in the above mentioned url, webcam is the product name which is placed in the url after rewriting.

3. Rewriting www.yoursite.com/user.php?username=xyz to www.yoursite.com/xyz :

You can rewrite your URL according to the Method of Directory type as mentioned above in the heading URL Rewriting Methods using this technique.


4. Redirecting the domain to a new sub folder of inside public_html :
Sometimes we create a folder inside the root directory Suppose If you want to redevelop your site, you can place the new site into the folder named new_site. It means all the files of redeveloped site is placed inside the root directory of folder named new_site.
Here you need to understand that there can be a mess to paste all the files in the root folder (or can be a hectic process), so we don?t have this option. It means now your website can only be assess by http://www.yoursite.com/new_site.
So after placing the following code into the .htaccess file , you can access ?www.yoursite.com?, whose files are actually placed in the new folder.
Look at the below code ….
5. Redirecting without www URL to www URL :
Sometimes you might have noticed that when you type facebook.com, you will be redirected to the www.facebook.com. If you want this type of URL Redirection you can use the below code:

That’s it !!!

No comments:

Post a Comment