SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2005
    Location
    Los Angeles
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Another .htaccess problem..

    Hello,
    I have the following entry:

    RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ /category.php?cat=$1&subcat=$2&subcat2=$3&page=4 [L]

    I need the last "(.*)/" (&page=4) to be optional

    it works perfectly in this form:

    RewriteRule ^(.*)/(.*)/(.*)/$ /category.php?cat=$1&subcat=$2&subcat2=$3 [L]

    But it excludes pagination, witch is not on every result page

    Please advice

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,426
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    regex everything atom

    Despite your statement that
    Quote Originally Posted by Vadim22
    it works perfectly in this form:
    I can bet that it's much more likely that you just haven't noticed any problems yet. If I had a dollar every time I saw an example of a regex with the accursed "everything" atom and the problems it's use caused, my vices would be paid for.
    Please do yourself a favor and take a look at dklynn's site http://datakoncepts.com/seo
    Believe me, you do NOT want the regex to say
    beginning with anything and everything (that includes slashes too) followed by a slash followed by anything and everything (that includes slashes too) followed by a slash followed by anything and everything (that includes slashes too) etc etc ending with a slash.

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

    It's really frustrating to see (.*) routinely abused. I rant and rave and it does no good (okay, there are exceptions as a few do take the time to learn and they quickly see why it has limited appropriate use)!

    There is ONE RULE at the heart of mod_rewrite: Regular Expressions (regex).

    If you don't understand regex, don't use mod_rewrite!

    90% or more of those who use (.*) just use that because they know it will match something, anything, or nothing at all) only do so because they don't understand regex. These people should not use mod_rewrite!

    How's that for another rant?

    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

  4. #4
    SitePoint Zealot
    Join Date
    Oct 2005
    Location
    Los Angeles
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Quote Originally Posted by Mittineague View Post
    Please do yourself a favor and take a look at dklynn's site http://datakoncepts.com/seo
    Awesome reading, exactly what i was looking for.

    Thanks a lot!


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
  •