Page 1 of 1

[resolved] Apache rewrite for front-controller

Posted: Tue Jun 22, 2010 3:51 pm
by thinsoldier
How to change this so I don't have to list every folder/file I want access to?

Here's what I'm currently using.

RewriteCond $1 !^(index\.php|admin|adminmvc|common|contentimg|css|scripts|lib|parts|pages|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Currently I have to manually list the exact files/folders that I don't want to be redirected.


I want any path that doesn't exist to be sent to index.php
Any folders or files that do exist should go to the requested location without me having to list each one in the .htaccess

Re: Apache rewrite for front-controller

Posted: Tue Jun 22, 2010 3:58 pm
by AbraCadaver
Check the mod rewrite docs. -d is a dir and -f a file. Use one or both:
[text]RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f[/text]

Re: Apache rewrite for front-controller

Posted: Wed Jun 23, 2010 2:14 pm
by thinsoldier
Thanks

Code: Select all

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
# RewriteRule . /index.php [L]
RewriteRule ^(.*)$ /index.php/$1 [L]
www.chrisabernethy.com wrote:In the preceding example, the rewrite engine is enabled, and two conditions are used to determine whether or not to run the rewrite rule. The first checks to see if the requested resource is not a file, and the second checks to see if the requested resource is not a directory. If both checks pass (ie: the resource does not exist), the rewrite rule will be executed and the file '/index.php' will be served. Depending on what your application requires, your actual rewrite rule may differ slightly. For example, the Zend Framework requires that the original request be fed back into the central dispatch file like this:
RewriteRule ^(.*)$ /index.php/$1
Which means http://www.example.com/news/view/336/ becomes http://www.example.com/index.php/news/view/336/

And I can have somewhat separate sites under the /admin/ and /employees/ directories, each with their own front controller (and the same .htaccess rules in each directory)