views:

61

answers:

3

OK, so we were working in the wrong directory, meh!

We have a .htaccess file that is setup to redirect some files to a php script. Now we are adding some hard files which we want to bypass this redirect. So far this does not seem to be working and we are stumped.

Below is our initial .htaccess file contents after starting the engine which is working for another app already:

RewriteCond $1 !^(index.php|robots.txt|favicon.ico)

RewriteRule ^(.*)$ /index.php/$1 [L]

We are trying to load files now from /directory/ So we have tried adding each of these to the RewriteCond section:

RewriteCond %{REQUEST_URI} !directory

RewriteCond $1 !^(index.php|i/|robots.txt|favicon.ico|directory)

Neither seems to be working. Any ideas on how to get this to load?

Examples:

Should redirect

http://site.com/thisredirects/

Should not redirect

http://site.com/directory

http://site.com/directory/

http://site.com/directory/index.php

etc.

A: 

have you tried making a second .htaccess file in the /directory dir and doing a NoRewrite in it?

Zak
+1  A: 

Try this:

Wont redirect

RewriteRule directory/.* - [L]

Redirects

RewriteRule ^$ thisredirects/ [L]
RewriteRule (.*) thisredirects/$1 [L]
lemon
A: 

It seems you want to redirect anything that isn't actually an existing file in your docroot to your index.php. This little bit of rewrite should handle that:

RewriteCond %{REQUEST_FILENAME} -s [OR]  # file with size
RewriteCond %{REQUEST_FILENAME} -l [OR]  # file is a link
RewriteCond %{REQUEST_FILENAME} -d       # file is a directory
RewriteRule ^.*$ - [NC,L]                # don't rewrite [last rule]
RewriteRule ^(.*)$ /index.php/$1 [NC,L]       # everything else gets sent to index.php

The [OR] operator may be what you are looking for on the RewriteCond as well.

Also if you just want to whitelist the /directory portion you could put a Rule before your redirects that is marked [L] for "last rule"

RewriteRule ^/directory.*$ - [NC,L]
gnarf