Mod Rewrite/RegEx

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

Moderator: General Moderators

Post Reply
aliasxneo
Forum Contributor
Posts: 136
Joined: Thu Aug 31, 2006 12:01 am

Mod Rewrite/RegEx

Post by aliasxneo »

So I have some rewriting in my .htaccess but I wish to make an exception. First of all, how do I make an exception? What I mean is let's say if the url is pointing to an EXE file than I want it to process like normal and ignore all rewriting rules below it. Here's what I currently have:

Code: Select all

RewriteEngine on
RewriteRule ^([A-Za-z].*)/ index.php?query=$1 [nc]
 
What I want to do is for all requests that have a valid file extension at the end of them, process them like normal instead of passing them to /index.php. So my questions are:

1) How do I make exceptions with Rewrite?
2) What RegEx can I use to check if the given URL has a valid file extension at the end?

Thanks in advance :)
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: Mod Rewrite/RegEx

Post by prometheuzz »

aliasxneo wrote:So I have some rewriting in my .htaccess but I wish to make an exception. First of all, how do I make an exception? What I mean is let's say if the url is pointing to an EXE file than I want it to process like normal and ignore all rewriting rules below it. Here's what I currently have:

Code: Select all

RewriteEngine on
RewriteRule ^([A-Za-z].*)/ index.php?query=$1 [nc]
 
What I want to do is for all requests that have a valid file extension at the end of them, process them like normal instead of passing them to /index.php. So my questions are:

1) How do I make exceptions with Rewrite?
2) What RegEx can I use to check if the given URL has a valid file extension at the end?

Thanks in advance :)
I have never used Apache's mod_rewrite, but the regex you posted:

Code: Select all

^([A-Za-z].*)/
will not match a file, but a directory, since it should end with a '/'.


The following regex:

Code: Select all

^.*\.(?!exe$)\w*$
will match any String, except if it ends with .exe
Post Reply