Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    159
    Thanks
    2
    Thanked 15 Times in 15 Posts

    Mod_Rewrite With A Possible Second Directory

    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:


    domain.com/share/asdfghg/asdffgher
    OR
    domain.com/share/asdfghg

    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!
    Jordan
    Remember The Thank You Button Is Your Friend =]

    [ PHP / Javascript / VisualBasic / HTML / DHTML / CSS / .NET / MySQL ]

  • #2
    Regular Coder thesmart1's Avatar
    Join Date
    Dec 2005
    Posts
    369
    Thanks
    7
    Thanked 3 Times in 3 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    159
    Thanks
    2
    Thanked 15 Times in 15 Posts
    Thanks for the suggestion... I'll have a look later
    Remember The Thank You Button Is Your Friend =]

    [ PHP / Javascript / VisualBasic / HTML / DHTML / CSS / .NET / MySQL ]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •