Mod rewrite Tutorials
overview - syntax - basic - medium - advanced
Mod Rewrite Basic tutorials
The majority of you came to this site to find out how to do one of these
basic tutorials. So lets go ahead and line up what we'll be learning.
Tutorial 3
File and file Extension rewrites
These rewrites in this tutorial are helpful when you are changing
old static .html files into a more dynamic server side scripting
file like .asp, .jsp, .cfm or .php. Some of these also fall under
the "if I did this it would look cool" category. Enjoy!
Scenario 1:
We have a dynamic site using .php
extensions. We just want to make the site look less dynamic and
more like hand made. All the file names are staying the same, we
just want to change the extensions to .html.
.htaccess code RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.php $1.html [R=301,L]
RewriteRule ^(.*)\.html $1.php [L]
Like in tutorial 2 when we change files we need to use a 301 to
point users and search engines to the new files. The first rewrite
rule will do the redirect to the new files.
The second rewrite rule will call the .html's matching php file
as an alias. Think of the file alias as allowing you to substitute
any file you want on the server. In our case we're going to substitute
somefile.php for somefile.html. We get all the dynamics from a
.php file and the user has no clue at all.
Practical uses for scenario 1
- To change your file extensions smoothly.
- To alert search engines to updated files on your site.
Scenario 2:
We own a music store online. For
our cd catalog online we want to change the file extensions from
.php to .cds. We think users will get a laugh if the call up the
file /catalog/metalica.cds .
First we'll have to change our files to out put a .cds instead
of .php. Then all you need is this code
.htaccess code RewriteEngine On
RewriteBase /
RewriteRule ^catalog/(.*)\.php catalog/$1.cds [R=301,L]
RewriteRule ^catalog/(.*)\.cds catalog/$1.php [L]
Ok I know it's redundand but I know people want to know how to
do this. I'm sure any of you porno boys that learn this rewrite
will have fun. I'm sure your visitors will think you're the bomb
when they show up to your site tomorrow and all your file extensions
have been changed to .xXx .
Practical uses for scenario 2
- To look cool to your customers
- Come on I know you hacker boys would get a blast out of changing
a victims file extensions to .dork or worse. Though this isn't
very practical it would sure be funny to find cnn.com hacked
and all it's extensions changed to .fox .
<< mod rewrite syntax :: basic
mod rewrites :: medium mod rewrites >> |