Forum Moderators: phranque

Message Too Old, No Replies

RewriteCond %{REQUEST_URI}

         

ebaudais

5:55 pm on Aug 1, 2004 (gmt 0)

10+ Year Member



I am wanting to rewrite a CGI script from the cgi-bin to the root directory. I am wanting to exclude certain types of files, like CSS, from being rewritten from the root directory. I have tried the following rewrite rules in .htaccess in the root directory to no avail.

RewriteEngine On

RewriteCond %{REQUEST_URI}![^\.css]+$
RewriteRule $ /cgi-bin/script.cgi/ [L]

I have tried just the rewrite rule by itself and it works.

Can someone help me with getting this rewrite condition correct?

jdMorgan

6:57 pm on Aug 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ebaudais,

Welcome to WebmasterWorld [webmasterworld.com]!

The [] characters enclose a list of characters, any one of which is an acceptable match. That is, [abc] means match a character which is equal to a, b, or c. Preceding this list of characters with "^" means NOT, so [^abc] would mean "Match any character except a, b, or c. Neither of these is what you want to do, so try:


RewriteCond %{REQUEST_URI} !\.css$

In order to specify multiple filetypes in your exclusion, use "alternation" to allow several alternates:

RewriteCond %{REQUEST_URI} !\.(css¦inc¦js)$

I'm not sure about your RewriteRule, as I don't know what URL-path you might want to match with a pattern of "$", but this demonstrates the RewriteCond function I think you are looking for.

Note that posting on this board changes solid pipe characters to broken pipe "¦" characters. You must edit the code and change them back before attemping to use the code.

See the link to a regular expressions tutorial in our Apache forum charter [webmasterworld.com] for more info on mod_rewrite patterns.

Jim

ebaudais

10:06 pm on Aug 1, 2004 (gmt 0)

10+ Year Member



I am wanting to match just the root URL. I have tried a different Rewrite rule and got it to work.

RewriteEngine On

RewriteCond %{REQUEST_URI}!\.(css¦png¦gif)$
RewriteRule ^/$ /cgi-bin/script.cgi/ [L]
RewriteRule ^(/.*)?$ /cgi-bin/script.cgi$1 [L]

Thanks for your help!

jdMorgan

1:18 am on Aug 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it working! Be aware that RewriteCond(s) only apply to the single RewriteRule that follows them.

Jim