I can't figure out this simple redirect!

Jan 26, 2010 at 1:22 AM
Edited Jan 26, 2010 at 1:23 AM

Hi,

I'm migrating a site from Apache to IIS, so I'm using this rewriter.

 

All I want is for the server to check if the requested file exists (like global.css, or js/global.js), and if it does, return the file, otherwise send to index.php with the original url query string.

 

How can I do this?

 

Thanks.

 

FYI, Apache code to accomplish this:

 

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]

Coordinator
Jan 26, 2010 at 6:17 AM

There's no -l flag in IIRF.  (For links)  Comment that line out. (prefix with #)

Everything else works, unchanged.

 

Jan 27, 2010 at 7:24 PM

This is what I have now:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]

It does not work. All request go to index.php, even if a requested file exists. What I need is to check if the request is an existing file, is so deliver the file, other wise send to index.php with url unchanged.

 

Thanks.

Jan 27, 2010 at 8:19 PM

This seems to be working for me:

RewriteEngine On
RewriteCond %{HTTP_URL}             (/|\.foo|\.htm|\.php|\.html|/[^.]*)$   [I]
RewriteCond %{REQUEST_FILENAME}     !-f                                    
RewriteCond %{REQUEST_FILENAME}     !-d                                    
RewriteRule ^.*$                    /index.php                      [U,I,L]