View Full Version : Mod_Rewrite With A Possible Second Directory

06-01-2008, 11:01 PM
I realise I post tooo many questions about mod_rewrite but it's the thing I hate most about apache! :)

Right two links. I could put:


I want BOTH to refer to domain.com/external/share.php?f=$1&ses=$2

However $2 may not be there, it can be blank.

The closest I got was:

RewriteRule ^share/(.*)/(.*)$ external/share.php?f=$1&ses=$2 [NC]

Which works fine but if you don't have $2.. you MUST have a trailling slash, and this may not be the case.

Cheers again guys!

06-02-2008, 01:53 AM
You could try using two rules. Use something like this for a second one:
RewriteRule ^share/(.*)$ external/share.php?f=$1
It'll check the first one, do nothing if there's no trailing slash, then check the second one (which allows for no slash).

Hope this helps. I admit though, I haven't done enough with mod_rewrite to be very experienced, myself.

06-02-2008, 02:03 AM
Thanks for the suggestion... I'll have a look later :)