View Full Version : Mod_Rewrite With A Possible Second Directory

06-02-2008, 12:01 AM
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, 02: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, 03:03 AM
Thanks for the suggestion... I'll have a look later :)