Page 1 of 1

[SOLVED] RewriteRule issues

Posted: Sat Jun 30, 2007 7:10 pm
by HiddenS3crets
I use this code for my website

Code: Select all

RewriteRule ^([^"images"|"filemanager"][a-z]+)/?$ /index.php?section=$1
This code should read and be interpreted as
any sequence of letters that is not images or filemanager
The code works properly if I only have [a-z]+ in the parentheses, but when I add those special cases I start having problems; basically the script will work for some strings and not for others.

I cannot figure out why this is happening or exactly how it's deciding whether or not the string is ok.

Is my way of saying "ignore these names" not formatted properly or possibly there's something else going on?

Posted: Sat Jun 30, 2007 7:27 pm
by superdezign
Brackets make a character class.

PCRE - Regex for PHP

Posted: Sat Jun 30, 2007 8:15 pm
by John Cartwright
Moved to Installation and Configuration.

Posted: Sat Jun 30, 2007 8:18 pm
by Benjamin
Should be in Regex I would say.

Posted: Sat Jun 30, 2007 10:39 pm
by superdezign
astions wrote:Should be in Regex I would say.
+1

Posted: Sun Jul 01, 2007 1:09 am
by John Cartwright
We usually move mod rewrite related questions here, but whatever..

Moved to Regex.

Posted: Sun Jul 01, 2007 1:50 am
by Benjamin
Your regex is evaluating to:

[line start][any characters except [",i,m,a,g,e,s,|,",f,i,l,e,m,a,n,a,g,e,r,"]] followed by [repeated at least 1 time[one of the following characters [a to z]]][line end]

So then what you would need to do is create rules above this rule, that search for these 2 strings and then stop the rest of the rules from being processed.

That is my theory anyway.

:oops: Not really a 100% Regex issue after all. My bad.

This is now a "Miscellaneous" issue. :lol:

Posted: Sun Jul 01, 2007 5:53 am
by superdezign
astions wrote:Your regex is evaluating to:

[line start][any characters except [",i,m,a,g,e,s,|,",f,i,l,e,m,a,n,a,g,e,r,"]] followed by [repeated at least 1 time[one of the following characters [a to z]]][line end]

...

That is my theory anyway.

:oops: Not really a 100% Regex issue after all. My bad.
Hehe, you're closer than you think.

HiddenS3crets, character classes don't contain a sequence of characters, they contain a series of characters. Subpatterns contain a sequence of characters. And the pipe (|) means nothing in a character class, as well as quotation marks. The link I gave you should clear it up.

Posted: Sun Jul 01, 2007 3:01 pm
by HiddenS3crets
Ok, so I understand that I need to use subpatterns, but from what I've read subpatterns are things that need to be matched. How could I declare a subpattern that says "ignore these cases"?

Posted: Sun Jul 01, 2007 3:04 pm
by feyd
That's called a "negative assertion."

Posted: Sun Jul 01, 2007 3:16 pm
by HiddenS3crets
That's what I'm looking for :o

But of course the syntax (?!) isn't accepted in my RewriteRule. It returns an internal server error.

Posted: Sun Jul 01, 2007 3:17 pm
by feyd
Update your Apache install, they switched to PCRE in more recent builds.

Posted: Sun Jul 01, 2007 3:22 pm
by HiddenS3crets
I got it working using a different method... RewriteCond

Code: Select all

RewriteCond %{SCRIPT_FILENAME} !images|filemanager