[thelist] using mod_rewrite

evolt at markgroen.com evolt at markgroen.com
Thu Jun 1 00:08:20 CDT 2006


On Wed, 2006-05-31 at 16:36 -0600, Rich Points wrote:
> Hi List,
> Over the years I've read about mod_rewrite but I've never needed to  
> use it.  I think I have an application for it now.
>
> I'm setting up a new shopping cart that resides at a url something like
> www.mysite.com/shopping_cart/index.php
> and products are found
> www.mysite.com/shopping_cart/product_page.php
> When I make it live I would like that page to show up as
> www.mysite.com/index.php or www.mysite.com
> and product pages as
> www.mysite.com/product_page.php
>
> I'm pretty sure I can do this with mod_rewrite but I'm not quite  
> sure how to do it.  I know I need to edit the .htaccess  but not  
> exactly sure on the syntax.

In your htaccess file:

<IfModule mod_rewrite.c>
#turn it on first
RewriteEngine  on
#force start at public root
RewriteBase    /
#if there is no trailing slash after the URL, add one
RewriteCond $1 !/$
#repeat below as needed
RewriteRule    ^index.php$  shopping_cart/index.php
RewriteRule    ^product_page.php$  shopping_cart/product_page.php
</IfModule>

More info with lots of examples of different scenarios for using the
Swiss Army knife that comes with Apache:

http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

-- 
cheers,

         Mark



More information about the thelist mailing list