SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    590
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with mod rewrite rules

    Hello forums,

    Please help me with this mod rewrite rule:

    Code HTML4Strict:
    RewriteRule ^hitch/([A-Za-z0-9-]+).html/?$ hitch.php?action=make&year=$1 [NC,L]
    applies for: website.com/hitch/2001.html

    However my client wants the format to be website.com/hitch-2001.html. I tried:
    Code HTML4Strict:
    RewriteRule ^hitch-([A-Za-z0-9-]+).html/?$ hitch.php?action=make&year=$1 [NC,L]
    But it doesn't work

    Any ideas?

    Thanks
    Don't Panic

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,680
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    sd,

    Please use the [code] ... [/code] wrapper for your code.

    Code:
    RewriteRule ^hitch/([A-Za-z0-9-]+).html/?$ hitch.php?action=make&year=$1 [NC,L]
    That will give you problems because the /? in the regex will be interpreted as one of two subdirectory levels which will ruin your relative links (css, js, gif, jpg, etc). Then, what year has a letter in it? Why not (/d{4}) for the atom? That will match a four digit year value. If you're looking at 2000 - 2050, (20[0-5][0-9]). Specificity counts! Then, what the heck are you thinking about asking for No Case in a URI? That will not work for {REQUEST_URI}s because they ARE case specific! IMHO, don't use the NC flag except on {HTTP_HOST} unless you have a very good reason.

    To appease your client, use:
    Code:
    RewriteRule ^hitch-(20[0-5][0-9])\.html$ hitch.php?action=make&year=$1 [L]
    Lastly, you could use a tutorial like the one linked in my signature (with sample code).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    590
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks DK that works (as usual)
    "(20[0-5][0-9])" is cool but I have strings like 1990-to-2001 so I'm keeping "([A-Za-z0-9-]+)".
    Honestly I have no idea what NC means lol ... tnx for the info

    You Rock !
    Don't Panic

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,680
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    sd,

    OIC.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Tags for this Thread

Bookmarks

Posting Permissions

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