Skip to content

Instantly share code, notes, and snippets.

@simonewebdesign
Created May 5, 2014 21:31
Show Gist options
  • Save simonewebdesign/2b1090d9756855ed45ef to your computer and use it in GitHub Desktop.
Save simonewebdesign/2b1090d9756855ed45ef to your computer and use it in GitHub Desktop.
.htaccess redirect all requests to a subfolder
# /.htaccess
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public/$1 [L]
#----------------------------------------------------
# /public/.htaccess
# Put off automatic trailing slashes in directories
DirectorySlash Off
# Manually put back trailing slashes in directories
RewriteBase /
RewriteCond %{REQUEST_URI} ^((/?[A-Z][A-Za-z0-9]*)+[^/])$
RewriteRule ^((/?[A-Z][A-Za-z0-9]*)+[^/])$ index.php?page=$1 [L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^([a-z0-9][A-Za-z0-9/]*[^/])$ $1/ [R,L]
# Redirect all requests
RewriteRule ^(.*)$ $1 [NC]
# Handle errors
ErrorDocument 404 404frompublic.html
ErrorDocument 500 500frompublic.foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment