Page 1 of 1

mod_rewrite help

Posted: Sun Sep 11, 2005 3:41 pm
by pickle
Hello everyone,

I'm having difficulty wrapping my head around mod_rewrite for my home-rolled gallery script. I'm on a shared host, so all my web-viewable files are in the /home/my_user/public_html/ directory. I've got a sub-directory of that called browser. I want to put some .htaccess restrictions on that directory, so that a call to http://www.mydomain.ca/browser/Camping/Card1 will actually point to http://www.mydomain.ca/browser/index.ph ... ping/Card1.

I thought I had it figured out with this file:

Code: Select all

RewriteEngine on

RewriteBase /browser/

RewriteRule ^/(.*)$ http://www.mydomain.ca/browser/test.php?path=$1 [R,L]
But that doesn't work - likely because I'm stabbing in the dark. I have a few questions still.
  • What exactly does RewriteBase do? From what I've read, that's the subdirectory where the RewriteRule starts its work. If I've got the .htaccess file sitting in /home/my_user/public_html/browser/, what should I have for the RewriteBase?
  • Is that regex going to work?
Thanks for any advice you guys have got.

Posted: Sun Sep 11, 2005 11:16 pm
by anjanesh
Does this work ?

Code: Select all

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+) test.php?path=$1/$2

Posted: Mon Sep 12, 2005 10:16 am
by pickle
The two folders was only an example. After /browser/ there can be any number of directories, so the $1/$2 thing won't necessarily work. If I can just get everything after /browser/ to be included as a GET var, I can pull it apart in PHP.

Thanks though.