Tricky URL rewrite problem


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:[^/])/([^/])/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.

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


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


What? Successfully processing URI’s like 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 :kaioken: EVERYTHING :kaioken: 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.



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


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.