New to this, ignore folders

Apr 6, 2011 at 2:34 PM

I've rewritten some links to something like:, which translates to

or, which translates to

This is the rule that handles it and is working ok, or it seems to.

RewriteRule ^(.*)/(.*)/pid/(.*)$ /$1/$2.php?np=$3 [L,I]

There are a few folders that I need this rule to ignore

_cmsscripts | _cmslibrary

How do I do this?

This is my full iirf.ini

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !^/(_sitefiles|_cmslibrary|_cmsscripts)/ [L] #tried this not working

# Incoming URL                      Expected Result
RewriteRule ^(.*)/(.*)/pid/(.*)$ /$1/$2.php?np=$3 [L,I]


Apr 6, 2011 at 3:14 PM

You can use a negative lookahead assertion in the regex, using (?!_cmsscripts|_cmslibrary).   It asserts a positive match for the entire regex, only if it the parenthesized sub-pattern does not match.

So your rule might be

RewriteRule ^(?!_cmsscripts|_cmslibrary)(.*)/(.*)/pid/(.*)$ /$1/$2.php?np=$3 [L,I]


Apr 6, 2011 at 3:31 PM

Mmmm, I gave that a try but it didn't seem to work. this is the link that is causing the problem:

it should just be:-

Apr 7, 2011 at 3:21 PM

Well sure, the rule I suggested won't work if the incoming URL path starts with /index/pid.  Just look at the regex.  It's obvious. I know regex can be confusing, but to use IIRF effectively, you need to be able to at least read relatively simple ones. 

When you said, "There are a few folders that I need this rule to ignore", you didn't specify just where in the URL path the _cmsscripts or _cmslibrary would be found, so I just guessed when I suggested the rule.  You'll have to decide for yourself where to put the option in the regex, as is appropriate for the URLs you need to handle.  Like I said, this is going to require at least a basic understanding of regex.  Don't just take my suggestion as "the answer";  think about what I'm suggesting and then intelligently apply it to your situation. After all, you understand your situation much better than I do.

Also - I don't know what you mean by "it should just be...".    What is IT, in this case?   The incoming URL?  If so, what should it get rewritten to?  Is "IT" the URL that it gets rewritten to?  In that case, what is the incoming URL?  You need to be specific and precise in what you want.  

Something that may help you think about your situation, and also explain it to others, is to just write out a table of URLs, examples of incoming URLs, and what you need to rewrite them to.  If you need NO REWRITE for an incoming URL, then write an entry in the table that says so.   You started with this approach in the first message (eg /index/pid/9 gets rewritten to index.php?np=9  , ...etc...) , but then your additional requirements regarding the folders stepped away from that "A->B" approach.   I think doing this would help clarify things for you, and for me, too.