Skip to content

Instantly share code, notes, and snippets.

@satooshi
Created September 2, 2012 14:49
Show Gist options
  • Save satooshi/3599884 to your computer and use it in GitHub Desktop.
Save satooshi/3599884 to your computer and use it in GitHub Desktop.
mod_rewrite for front controller
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# skip existent files
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule index.php - [QSA,L,C]
RewriteRule .* - [QSA,L]
# deny access php files
RewriteCond %{REQUEST_URI} ^.*\.php$
RewriteRule ^.*\.php$ - [R=404,L]
# asset
RewriteCond %{REQUEST_URI} ^asset/*$
RewriteRule ^asset/*$ - [QSA,L]
# redirect root access (/) to index.php
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^$ index.php [QSA,L]
# redirect 404 for non existent files
RewriteCond %{REQUEST_URI} ^(.*)\..*$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\..*$ - [R=404,L]
# no, so we redirect to our front web controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment