SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Jul 2007
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Tricky URL rewrite problem...

    Hello,

    I have an URL rewrite that I've been using successfully for years:
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/articles/([^/]*)/([^/]*)/$ /articles.php?a=$1&b=$2&c=$3&d=$4&e=$5 [L]

    I developed a un-related new feature on our site that had unintentional conflicts with this re-write. I allowed members to dynamically create directory-styled URLs on their pages for better organization and SEO-friendly URLs:
    mydomain.com/memberpage/([^/]*)/([^/]*)/articles/

    One directory that a member created was: "articles", which fires off the re-write above and screws up the page. It's an extremely rare coincidence that a member named the 4th level directory of their page: "articles", which is the only thing that could conflict with my rewrite script.

    Question:
    What can I do in my top re-write script to ignore rewriting if the 1st level directory is "memberpage", because this word will always be fixed for all members

    Thanks

  2. #2
    SitePoint Addict
    Join Date
    Jul 2007
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind, I'm pretty sure I figured it out.

    I added this before the rewrite:
    RewriteCond %{REQUEST_URI} !^/?(memberpage)/

    This seems to be working good so far.

    Thanks for looking anyways.
    Kind regards

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

    What? Successfully processing URI's like example.com////articles///? YGBSM! You're just lucky that you don't have an articles.php located in your server's root directory (the first place Apache looks for /articles.php?yadda=yadda).

    Okay, so I blew off some steam over the inappropriate use of the * metacharacter (should have been a + to ensure at least one non / character).

    Now, from your next statement, you should have no problem because the link shown does not have three /'s after articles.

    Okay, okay, memberpage can use articles as a directory so you could have a problem ... unless you exclude the first subdirectory if it's memberpage, i.e., RewriteCond %{REQUEST_URI} !^memberpage/.

    Now, I must expect you to change the specification on this to say that memberpage is not a static entry for members but could be every member's name or other identifier. In that case, you'll need to list the offending members (those using articles/) using either RewriteCond %{REQUEST_URI} !^(member1|member2|...|membern)/ OR replace this list with individual RewriteCond statements (as above) linked with [OR] flags.

    What you've encountered is the reason that I typically leap up and down on specificity, i.e., specifying the exact content you want to match and coding that into your mod_rewrite (WITHOUT using the EVERYTHING atom or its close relatives ... like ([^/]*) ).

    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.

    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 Addict
    Join Date
    Jul 2007
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Greetings dklynn,

    Thanks for the info, I will take a look at your tutorial. Also, the "memberpage" example will be a static folder name which will never change.

    When I first developed the site, I knew nothing about PHP/MySQL and mod_rewrite. I simply had to develop my own ideas and slapped things together until everything was working the way I wanted. Years later with more experience, I've been getting much better, more efficient and more used to terminologies. I'll have to study up on mod_rewrite some day. I don't need to use it very often except for simple 1 variable SEO URLs for my newer sites.

    Kind regards

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

    If you're now into PHP, don't be scared off by the regex possible there. The subset of regex which is used by mod_rewrite is quite simple and very straight forward. One pass through my signature's tutorial will get you fully prepared for nearly all webmaster tasks (RewriteMaps are an Administrator task). Better yet, the examples (with code) at the end of the tutorial will demonstrate common tasks brought here by members over many years.

    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


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
  •