A to Z about Search Engine Optimization (SEO), a Internet Marketing Hand Book. In Jag's SEO a day help blog, SEO articles & tips are put together for free to educate SEO newbie’s, web designers, online business owners and seasoned SEO professionals. You're welcome to follow the blog for search & social media best practices. Thank you for visiting the SEO Help blog.

Thursday, May 08, 2008

Create Search Engine Friendly URLs using .htaccess


In this post, we will see how to use .htaccess to create search engine friendly URLs. Using .htaccess, mapping dynamic pages to static address is easy and this helps search engines to index the pages fast, effective and strong.

Initially, create a file .htaccess in your favorite editor, use the rewrite rule as below to map dynamic id passing url's to static version. Use the code and create your dynamic pages for search engines spiders

**************************************************************
RewriteEngine on

## Rewrite Rules ##

RewriteRule ^category/([0-9]*)/([0-9]*)/([a-z_]*)$ category.php?id=$1&page_id=$2 [L]
RewriteRule ^category/([^/]*)/([a-z_]*)/([^/]*)$ category.php?r_name=$2&id1=$1


***************************************************************

For eg: Originally the page URL looks like subcategory.php?id=5&page_id=1

Using the above .htaccess code, you can create the URL as

category/5/1/product_name

Here,

RewriteRule ^category/([0-9]*)/([0-9]*)/([a-z_]*)$

^ - Refer to start
Category - creates a folder as mentioned name
/ - Used for virtual partition
[0-9] - Writes single number as folder name
[0-9]* - Writes n numbers as folder name
[a-z_] - Writes single letters as folder name
[a-z_]* - Writes letters as folder name
$ - Refer to end


Additional information:

Your id passing pages might have indexed through some referral and so, you can use the below code to avoid error pages, create a 404pagenotfound.php and add your a message to your visitors to navigate to home page for information’s

*****************************************************************

## Trace Errors
ErrorDocument 404 /404pagenotfound.php


*****************************************************************

Hope you will like the post and its useful :)

Share with your friends:
Add to Google Netvibes Add to My Yahoo! Windows Live Bloglines Newsgator

4 comments:

Rob said...

Thanks just tried and works perfectly, bookmarked

internet marketing services said...

i appreciate the tips. i also tried it and bookmarked the pages. great stuff!

Seo Expert said...

It's something new,i will try it..Thanks!!

WordPress SEO said...

Very informative post.Thanks for your advice.