Forum Moderators: phranque

Message Too Old, No Replies

Redirect for a directory that exists and is set to deny from all

         

engenius

9:56 pm on Apr 12, 2012 (gmt 0)

10+ Year Member



I have setup codeigniter (a php framework) and I am using their recommended htaccess file:

RewriteEngine on
RewriteCond $1 !^(index\.php|css|images|favicon\.ico|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

This works great except for one thing. www.example.com/application does not redirect to www.example.com/index.php/application because the framework is stored in a folder titled application and the folder contains an htaccess file that says deny from all.

Thank you for any suggestions.

lucy24

11:06 pm on Apr 12, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteCond $1 !^(index\.php|css|images|favicon\.ico|js|robots\.txt)

"The full name of the requested file does not begin with 'css' or 'js' "

Are you positive that's what it says?

www.example.com/application does not redirect to www.example.com/index.php/application because the framework is stored in a folder titled application and the folder contains an htaccess file that says deny from all

It doesn't redirect, or it does redirect and then slams into a 403?

Oh, wait, rewind. Is it
[L] alone (Rewrite)
or is it
[R=301,L] (Redirect)
?

A Rewrite and a Redirect are different things. Which one is happening here? Or, more to the point, which one is supposed to be happening?

g1smd

11:29 pm on Apr 12, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The js, images and css entries are to stop requests for the /js/, /images/ and /css/ folders from being redirected. Hint: no end anchoring. :)

Requests for WMT account verification will be incorrectly redirected as will Google's 404 checker that asks for random URL beginning
example.com/noexist_

engenius

1:03 am on Apr 13, 2012 (gmt 0)

10+ Year Member



g1smd is correct that those folders should not be redirected and that part works correctly.

The htaccess file I pasted is just the default codeigniter file. I did not include what I am attempting to do.

I think this is what I want, but it does not work:

RewriteRule ^/application$ /index.php/application [L]

I want to rewrite this one specific example manually so that it redirects to index.php instead of trying to open the application folder which contains all of the code for the website. The application folder contains its own htaccess file with the command deny from all so that no outsiders can access the application files.

What is happneing now is that I get a Forbidden page because it is trying to open the application folder. If the application folder did not exist, there would not be any issues. It seems to me that htaccess file in the application folder is doing its thing before the main htaccess file has a chance to redirect the url to index.php.

Edited to answer questions: I am positive that what I pasted works for every case except for www.example.com/application and it should be a rewrite, not a redirect. I was using the wrong terms.

lucy24

9:07 am on Apr 13, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteRule ^/application$ /index.php/application [L]


Is "application" an extensionless filename or a directory? If it's a directory, it won't work with the closing anchor $

It seems to me that htaccess file in the application folder is doing its thing before the main htaccess file has a chance to redirect the url to index.php.

htaccess files are processed from outermost to innermost, one module at a time. A request for /application should never even reach the directory-- unless there's a mod that executes before mod_rewrite and that's the mod that issues the 403. Can't be the "deny from" because that's core, so it won't happen until after every last mod has done its thing.

But if the request for /application comes through as /application/ or /application/morestuff then the Rewrite will never touch it.

And it really is important not to say "redirect" when you mean "rewrite". With a redirect, the request goes out the door and starts all over again as if it had never seen your server before. With a rewrite it just carries on to the next module.

You can use something like LiveHeaders to track your request and see exactly where it's going.