|
|
Making Search Engine Friendly URL by Ramil Alcibar An htaccess file is a simple ASCII file. .htaccess is the file extension. It is not filename.htaccess or anyfile.htaccess. It is simply named .htaccess. This file has many usage including password protection, enabling SSI, deny users by IP, changing your default directory page, making search engine friendly URLs, redirects, adding MIME types and many more. Search Engine Friendly URL http://www.mysite.com/view_computer.php?key=1 can be easily rewritten as http://www.mysite.com/computer_1.html thus eliminating the "?" sign in the URL. The example shown above referred to a module called mod_rewrite. This is a module compiled into Apache web server. This will be the usage of .htaccess file we talked earlier. mod_rewrite makes use of the .htaccess to perform rewrites which in turn tells the server how to convert between static and dynamic URLs. phpinfo(); save it as info.php, upload it to your server, then on your browser type http://www.mysite.com/info.php. It will display lots of information, just look for the heading "apache" and then "Loaded Modules" and you must see mod_rewrite there and proceed to creating the file. If you're just running th scripts in your local machine, open the Apache configuration file - httpd.conf file and find the following line: LoadModule rewrite_module Make sure that it has no comment sign (#) before it. Creating .htaccess http://www.mysite.com/view_computer.php?key=1 to http://www.mysite.com/computer_1.html Here's the code for .htaccess: RewriteEngine On Ok let's break it down. The first and second line is just a comment so no need to go through with it. Next I am forcing Apache to turn on the rewrite engine for the URL's using the RewriteEngine On.
You may be asking, where I'm going to put this or that. Let's say you have a database of computers and you have a page, say computerlist.php, that list all of it by name and each name has a link to view the detailed part of the computers listed. It may have the following code: // Some stuff of queries here.. Change "" . $name . ""; to "" . $name . ""; making your final code look like this: // Some stuff of queries here.. Don't stop right here, play with the .htaccess and you can have more complex dynamic URLs to change into a simple search engine friendly. Source URL: http://www.triphp.com/resources/ About The Author Ramil Alcibar is a contributor to TriPHP Webmaster Resources. Page: 1 |
|
|
Copyright © 2004 - 2006
TriPHP. All Rights Reserved. |

