Mod Rewrite, A quick overview
Posted: April 30th, 2004, 1:12 am
I have become a little comfortable Mod Rewrite after applying different versions of it to these forums. Mod Rewrite is something this forum implements, it "masks" the messy viewforum.php?foo=bar&foo2=bar2.
It's actually quite simple, all that you need is an apache based http server, and a text editor (notepad for windows, kate for linux.)
Start up your editor and put these lines in there, don't worry I'll explain later
Ok to start off,
This code just tells apache you will be "masking" some filenames.
The next line:
This tells apache that for every url of your site that has index.php?foo=***; it will be rewritten to index***.php
Save this file as .htaccess. If you are in windows, save it as htaccess.txt then upload it, and use your ftp client's rename function to rename it to .htaccess; or you can saveas .htaccess in notepad/wordpad.
So now whenever you want to pass variable "foo" with value "***" within your page simply link to indexfoo.php.
Other forms can be created, allowing multiple variables such as:
That just tells apache that index_bar_bar2_bar3.php really is index.php?foo=bar&foo2=bar2&foo3=bar3.
The reason for all of this is that it is easier for google to index your pages, and MORE pages will get indexed because index.php?foo=bar and index.php?foo2=bar2&foo3=bar3 are similar and don't count as much to your innersite links (correct me if I am wrong). But indexbar.php and index_bar2_bar3.php are two dissimilar links and are treated as thus.
It's actually quite simple, all that you need is an apache based http server, and a text editor (notepad for windows, kate for linux.)
Start up your editor and put these lines in there, don't worry I'll explain later

Code: Select all
RewriteEngine On
RewriteRule ^index(.*).php$ index.php?foo=$1 [L,NC]
Ok to start off,
Code: Select all
RewriteEngine On
This code just tells apache you will be "masking" some filenames.
The next line:
Code: Select all
RewriteRule ^index(.*).php$ index.php?foo=$1 [L,NC]
This tells apache that for every url of your site that has index.php?foo=***; it will be rewritten to index***.php
Save this file as .htaccess. If you are in windows, save it as htaccess.txt then upload it, and use your ftp client's rename function to rename it to .htaccess; or you can saveas .htaccess in notepad/wordpad.
So now whenever you want to pass variable "foo" with value "***" within your page simply link to indexfoo.php.
Other forms can be created, allowing multiple variables such as:
Code: Select all
RewriteRule ^index_(.*)_(.*)_(.*).php$ index.php?foo=$1&foo2=$2&foo3=$3 [L,NC]
That just tells apache that index_bar_bar2_bar3.php really is index.php?foo=bar&foo2=bar2&foo3=bar3.
The reason for all of this is that it is easier for google to index your pages, and MORE pages will get indexed because index.php?foo=bar and index.php?foo2=bar2&foo3=bar3 are similar and don't count as much to your innersite links (correct me if I am wrong). But indexbar.php and index_bar2_bar3.php are two dissimilar links and are treated as thus.