Ad

Howto Mod_rewrite Every Request To Index.php Except Real Files But Exclude One Real Directory?

- 1 answer

Let me explain my situation:

I'm using a MVC framework (CodeIgniter), so every request gets rewritten to my index.php file, which in turn routes this to my classes and functions.

Offcours if there are requests for real files they should not be processed by scripts but directly send from webserver to browser.

Owkay no problem, the following rewrite rules will do just that:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

I would like that requests for a certain folder (let call it 'private') still be processed by php. The reason for doing this is that i would then verify if the user is authenticated, and if so, send contents to browser.

  • Any apache gurus in the house who can assist?
  • Is this a acceptable solution to this the problem?
Ad

Answer

Try this rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond $1 ^private($|/)
RewriteRule ^(.*)$ index.php/$1 [L]

This will exclude any URL paths that are private or start with private/ even though they are existing folders or files.

Ad
source: stackoverflow.com
Ad