In this tutorial I will show you some simple .htaccess features. In this case mod_rewrite.
You may see on some websites, for example this one, where the URLs are very tidy and there is nothing like page.php?content=home it would just be page/home/. This is usually done through .htaccess, and it’s a lot more simple than you think.
First thing you need to do is create a file called “.htaccess” (without the quotes). This file actually has no name, its just a file extention. But thats a bit irrelivant. Also, its probably worth mentioning that you will not be able to create file on windows. You will have to create it on your web server.
Second thing to do is open it up then paste this code in it:
RewriteEngine On
What this does is allows us to do mod_rewrite. Then we need to add some rules. Firstly lets assume you have a file called ‘index.php’ and we want to rename that to ‘home’. You would add this code below the code we already have:
RewriteRule ^home$ index.php
So our full code is…
RewriteEngine On
RewriteRule ^home$ index.php
You can add as many rules as you like. There are more efficient ways of doing this but if you have never used .htaccess before its probably better to do this way, as its more simple.
Thanks for reading. :)






































October 2nd, 2008 at 9:45 pm
one little correction.
You can create a .htaccess file in Windows. If you in notepad save a file as “.htaccess” with the quotation marks you will be able to create the file in Windows.
//zekel
PS. I think you might have a small bug in your code. “PHP parsed this page in 1222979795.48 seconds.”, 1.2 billion seconds is quite a long time. DS.
October 2nd, 2008 at 9:48 pm
ops, forgot to say thank you.
//zekel
October 4th, 2008 at 4:49 am
Zekel is right, it can be created on Windows.
@Zekel: I emailed him about that. :P I thought it was funny, it took a few decades to load the page. XD
Another common use for mod_rewrite, besides hiding query strings, is to keep a user at either http://www.domain.com or just domain.com. Some people don’t like the http://www., so they force the user to use just the domain. Others do the exact opposite and always keep the http://www. in the URL.
Here’s the rewrite code to do this, it will redirect a user coming to http://www.domain.com to domain.com.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/1 [R=301,L]
(It should be noted that the above only works when using HTTP. A bit of alteration would be required to allow this to work with HTTPS aswell.
October 28th, 2008 at 3:22 pm
K94yk4 mloznzztvrug, [url=http://aennzethewxo.com/]aennzethewxo[/url], [link=http://ylqnvpswyjar.com/]ylqnvpswyjar[/link], http://isdltgyjohey.com/