Understanding mod_rewrite and the RewriteRule

mod_rewrite and the RewriteRule

Most people think that mod_rewrite and the RewriteRule are some kind of voo-doo that works sometimes and doesn't work at other times. Nothing could be farther from the truth!

This mindset is usually caused by a lack of understanding about Rules and Priorities and the basic mentality of "that's not the way I use to do it!"

Nonetheless, once you learn a few simple rules about the the RewriteRule and learn how simple and easy it is to convert your old redirect and redirectmatch rules, you just might fall in love with mod_rewrite and the RewriteRule!

Introducing mod_rewrite and the RewriteRule

Most people think that mod_rewrite and the RewriteRule are some kind of voo-doo that works sometimes and doesn't work at other times. Nothing could be farther from the truth!

This mindset is usually caused by a lack of understanding about Rules and Priorities and the basic mentality of "that's not the way I use to do it!"

Nonetheless, once you learn a few simple rules about the the RewriteRule and learn how simple and easy it is to convert your redirect and redirectmatch rules, you just might fall in love with mod_rewrite and the RewriteRule!

This tutor is designed to help you to find the EASY way to use this powerful tool! The following pages will teach you the easy way to convert your redirect and redirectmatch into a powerful RewriteRule!


Let's begin with a few common errors and a little understanding of why it doesn't work for you (after all, you have been searching the internet to try to get this right, right?).

Checking For Mod Rewrite

ALL the examples I give are tested both on my local server (FreeBSD) and on Pair Networks who also uses FreeBSD howbeit slightly older version than the bleeding edge server I have in my office! Of course we use the Apache server! This makes it easy to check for the Apache mod_rewrite using a simple PHP script!

Make A phpInfo file

Create a php file (I suggest you call it something like

<your initals>phpInfo.php

For Example:

SDphpInfo.php if your name is Snoopy Dog!

JCphpInfo.php if your name is Joe Cool or Jose Cruz!

Only One Line

You Only need to put one line in it...

<?php echo $_SERVER['HTTP_HOST']; ?>

Upload Your phpInfo File

You can upload it to any directory you want, I would suggest you use one that has your name, like JoseAdmin or SnoopyAdmin. I would also suggest you password protect it as this gives hackers information about your server!

Then just call your file with your browser... Something like...

http://example.com/JoseAdmin/JCphpInfo.php

The reason we use your name and initials here is to throw hackers off! There are plenty of websites out there with security issues with this file located at something like...

http://example.com/phpinfo/index.php

-OR-

http://example.com/phpinfo.php

You NEVER want to use a common name when dealing with your server configuration information.

Check For Mod Rewrite

Scroll down your phpinfo page and find the Section that says apache2handler. In that area you will find a row called Loaded Modules (no, they are not drunk!) and in Loaded Modules you need to see mod_rewrite! If it is there. you are good to go!

If mod_rewrite is not there, it is likely because the (guy|girl|alien) who loaded your server was also loaded at the time (I suggest you fire them!).

The Next (First) Step

Now that you have determined that you have mod_rewrite in your Apache server, we are ready to go on to the next step! Which is a little confusing because it is actually the First Step in our Tutorial! (It is beginning to sound like the module isn't the only one "loaded!") Anyway, it is now time for you to click on The First Step Link (which will actually take you to page three!)

Site Information

W3C Validation:

XHTML CSS

Site hosted by:

pair
networks

Page Colors:

-324- 

Database - ID Number:

-3-- 

Sponsorship Info:

A Collaborative Effort!

~ MANY THANKS! ~

Produced By:

Domain Names by Gamot Network

A Proud Sponsor of the...

Filipina! Campaign

Cooperation Links:

ACTS-29 Network

Version Number:

~ ~ Ver 1.00 ~ ~