tags:

views:

467

answers:

2

I'm writing some of my own rules for a few PHP scripts I'm writing, even though I have little experience with regexp. Note: little.

Basically I want to pass all URLs except a few as arguments to index.php, rewriting most URLs defined as slugs in a database.

ie: /admin, /config, /images, /lib and /template exists, but I do not want to be rewritten. But everything else, I want passed as arguments to index.php.

I'm doing this currently with:

url.rewrite-once = (
    "^/(.*)$" => "/index.php?$1"
)

Which works beautifully with the database slugs, however it also redirects the folders listed above. These contain files needed to be directly accessed, but I can't find anywhere describing how to exclude strings from a match.

Once I know how to do this, I can figure out the rest, but being new to regexp I don't know where to start.

Any help would be greatly appreciated.

Edit: I've since given these a shot:

"^/(index\.php|admin|config|images|lib|template)" => "$0",

For which FF reports an endless redirect for those folders;

"^/(?!(admin|config|images|lib|template))(.*)$" => "$0"

Doesn't match everything but the folders;

"^/([^(admin|config|images|lib|template)]*)$" => "/index.php?$1"

Again, doesn't rewrite anything;

"^/(.*)$" => "/index.php?$1"

Rewrites everything, including the folders which I don't want rewritten.

A: 

Try this:

url.rewrite-once = (
    "^/(index\.php|admin|config|images|lib|template)" => "$0",
    "^/(.*)$" => "/index.php?$1"
)
Gumbo
Unfortunately not, FF gives me an endless redirection error, which is also what I got when I tried a simple: "/template" => "/template"
ctrl_freak
+1  A: 

I seem to have achieved what I was looking for with the following expression:

"^/(?!(index\.php|admin|config|images|lib|template)).*$" => "/index.php?$0"

I then just

trim( $_SERVER['argv'] ,"/")

in index.php to get the slug.

ctrl_freak