[SOLVED] RewriteRule issues

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
HiddenS3crets
Forum Contributor
Posts: 119
Joined: Fri Apr 22, 2005 12:23 pm
Location: USA

[SOLVED] RewriteRule issues

Post 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?
Last edited by HiddenS3crets on Sun Jul 01, 2007 3:22 pm, edited 1 time in total.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Brackets make a character class.

PCRE - Regex for PHP
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Moved to Installation and Configuration.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Should be in Regex I would say.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

astions wrote:Should be in Regex I would say.
+1
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

We usually move mod rewrite related questions here, but whatever..

Moved to Regex.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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:
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
HiddenS3crets
Forum Contributor
Posts: 119
Joined: Fri Apr 22, 2005 12:23 pm
Location: USA

Post 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"?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

That's called a "negative assertion."
HiddenS3crets
Forum Contributor
Posts: 119
Joined: Fri Apr 22, 2005 12:23 pm
Location: USA

Post 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.
Last edited by HiddenS3crets on Sun Jul 01, 2007 3:20 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Update your Apache install, they switched to PCRE in more recent builds.
HiddenS3crets
Forum Contributor
Posts: 119
Joined: Fri Apr 22, 2005 12:23 pm
Location: USA

Post by HiddenS3crets »

I got it working using a different method... RewriteCond

Code: Select all

RewriteCond %{SCRIPT_FILENAME} !images|filemanager
Post Reply