Monday 30 November 2009

Search Engine-Friendly URL Generator & how to use/write .htaccess file for SEF URL

1. First of all, goto the /../apache/conf/httpd.conf file, try to find the with keyword ("rewrite_module"), you will get the line as
#LoadModule rewrite_module modules/mod_rewrite.so

uncomment(revode the # char at the beginning of line) the above line as
LoadModule rewrite_module modules/mod_rewrite.so

2. Then goto the root directory of your project, for example, samplesite at location htdocs/samplesite/. Then create the .htaccess (don't forgot to add dot(.) on filename) file on that location as htdocs/samplesite/.htaccess

3. Then write the following lines of code on that .htaccess file as;

/* ------------ .htaccess file ---------*/
---------------------------------------------------------------------------------
Options +FollowSymlinks
RewriteEngine on
RewriteBase /samplesite /* this /samplesite is base url of your project. */

/* then write the rule of your choice, sample rules as below */
RewriteRule searcharticle/(.*)/(.*)/(.*)\.html searcharticle.php?cat=$1&atitle=$2&aid=$3

RewriteRule viewarticle/(.*)/(.*) viewarticle.php?title=$1&aid=$2
---------------------------------------------------------------------------------

Then, save the .htaccess file with above data.

Here,
RewriteRule searcharticle/(.*)/(.*)/(.*)\.html searcharticle.php?cat=$1&atitle=$2&aid=$3
means ( we need to set article search URL in below format as )
http://localhost/samplesite/searcharticle/cat/articleTitle/24.html
=>(implies to )
http://localhost/samplesite/searcharticle.php?cat=catTitle&atitle=ArticleTitle&aid=24
(in normal PHP way without using of .htaccess code)

Similarly,
RewriteRule viewarticle/(.*)/(.*) viewarticle.php?title=$1&aid=$2
means ( we need to set article view URL in below format as )
http://localhost/samplesite/viewarticle/articleTitle/24
=>(implies to )
http://localhost/samplesite/viewarticle.php?atitle=ArticleTitle&aid=24
(in normal PHP way without using of .htaccess code)

This is the way to generate Search Engine-Friendly URL.
Also, here to Generator to make RULES for Search Engine-Friendly URL.

No comments:

Post a Comment

Please post any queries and comments here.