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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy regex help for mod_rewrite

    ok, first of all I would like to say I'm a regex IDIOT!. That being said, here's what I got:

    RewriteEngine On
    RewriteRule ^/([^/\.]+)/deals/([^/\.]+)/?$ index.php?key=$1&permalink=$2



    What I'm trying to do is match the following url request paths:

    /key-goes-here/deals/permalink-goes-here
    /key-goes-here/deals/permalink-goes-here/

    The string will always start with /
    The string may or may not end with /
    The "key-goes-here" part will always be alphanumeric and - (hyphens to separate words)
    The "permalink-goes-here" part will always be alphanumeric and - (hyphens to separate words)



    Thanks in advance

  • #2
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    660
    Thanks
    31
    Thanked 100 Times in 94 Posts
    Try something like this:

    Code:
    ^[A-Za-z0-9\-]+/deals/[A-Za-z0-9\-]+[/]?$
    I highly recommend you look into REGEX. I avoided it for the longest time but it, truthfully, saves a lot of time and effort while programming to match user input. I found the following two things to be very helpful resources:

    http://www.zytrax.com/tech/web/regex.htm
    http://weitz.de/regex-coach/

    Hope this helps!
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com


  •  

    Posting Permissions

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