mod_rewrite help

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

mod_rewrite help

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply