Jump to content

How does a Mod_Rewrite really work?


doubledee

Recommended Posts

This past Summer I had some help creating my first ever Mod_Rewrite so I could have "Pretty URLs" in my website!  8)

 

After several months away from the code, I would like to get some help making sure that I understand how things really work!!

 

Here is my Mod_Rewrite...

RewriteEngine on

#PRETTY:		articles/postage-meters-can-save-you-money
#UGLY:			article.php?title=postage-meters-can-save-you-money

RewriteRule articles/([a-zA-Z0-9_-]+)$ article.php?title=$1

 

 

This is my understanding of how things work, but please correct me if I am wrong!!

 

1.) A user clicks on the hyperlink www.MySite.com/articles/postage-meters-can-save-you-money

 

2.) Apache intercepts that URL and uses the Mod_Rewrite to transform things.  Specifically, the Mod_Rewrite converts my "Pretty URL" above to the following "Ugly URL" format...

www.MySite.com/article.php?title=postage-meters-can-save-you-money

 

3.) From this point forward, the Browser and my PHP script will always be working with the "Ugly URL"...

www.MySite.com/article.php?title=postage-meters-can-save-you-money

 

4.) But to the user, they will always see the "Pretty URL"...

www.MySite.com/articles/postage-meters-can-save-you-money

 

So if my PHP article template wants to display the article, it will need to use...

($_GET['title'])

...to locate the article in the transformed URL and then query MySQL to find said article.

 

Does all of the above sound correct or not?

 

Thanks,

 

 

Debbie

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.