Skip to content

Instantly share code, notes, and snippets.

@bzerangue
Last active December 14, 2016 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bzerangue/3820302 to your computer and use it in GitHub Desktop.
Save bzerangue/3820302 to your computer and use it in GitHub Desktop.
Symphony .htaccess files / nginx rewrite files
### Symphony 2.2.x ###
Options +FollowSymlinks -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /'.$rewrite_base.'
### SECURITY - Protect crucial files
RewriteRule ^manifest/(.*)$ - [F]
RewriteRule ^workspace/utilities/(.*).xsl$ - [F]
RewriteRule ^workspace/pages/(.*).xsl$ - [F]
RewriteRule ^(.*).sql$ - [F]
### DO NOT APPLY RULES WHEN REQUESTING "favicon.ico"
RewriteCond %{REQUEST_FILENAME} favicon.ico [NC]
RewriteRule .* - [S=14]
### IMAGE RULES
RewriteRule ^image\/(.+\.(jpg|gif|jpeg|png|bmp))$ extensions/jit_image_manipulation/lib/image.php?param=$1 [L,NC]
### CHECK FOR TRAILING SLASH - Will ignore files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]
### URL Correction
RewriteRule ^(symphony/)?index.php(/.*/?) $1$2 [NC]
### ADMIN REWRITE
RewriteRule ^symphony\/?$ index.php?mode=administration&%{QUERY_STRING} [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^symphony(\/(.*\/?))?$ index.php?symphony-page=$1&mode=administration&%{QUERY_STRING} [NC,L]
### FRONTEND REWRITE - Will ignore files and folders
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*\/?)$ index.php?symphony-page=$1&%{QUERY_STRING} [L]
</IfModule>
######
### Symphony 2.3.x ###
Options +FollowSymlinks -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
### SECURITY - Protect crucial files
RewriteRule ^manifest/(.*)$ - [F]
RewriteRule ^workspace/utilities/(.*).xsl$ - [F]
RewriteRule ^workspace/pages/(.*).xsl$ - [F]
RewriteRule ^(.*).sql$ - [F]
RewriteRule (^|/)\. - [F]
### DO NOT APPLY RULES WHEN REQUESTING "favicon.ico"
RewriteCond %{REQUEST_FILENAME} favicon.ico [NC]
RewriteRule .* - [S=14]
### IMAGE RULES
RewriteRule ^image\/(.+\.(jpg|gif|jpeg|png|bmp))$ extensions/jit_image_manipulation/lib/image.php?param=$1 [L,NC]
### CHECK FOR TRAILING SLASH - Will ignore files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]
### URL Correction
RewriteRule ^(symphony/)?index.php(/.*/?) $1$2 [NC]
### ADMIN REWRITE
RewriteRule ^symphony\/?$ index.php?mode=administration&%{QUERY_STRING} [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^symphony(\/(.*\/?))?$ index.php?symphony-page=$1&mode=administration&%{QUERY_STRING} [NC,L]
### FRONTEND REWRITE - Will ignore files and folders
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*\/?)$ index.php?symphony-page=$1&%{QUERY_STRING} [L]
</IfModule>
######
# nginx configuration
location ~ ^/'.$rewrite_base.'/manifest/(.*)$ {
return 403;
}
location ~ ^/'.$rewrite_base.'/workspace/utilities/(.*).xsl$ {
return 403;
}
location ~ ^/'.$rewrite_base.'/workspace/pages/(.*).xsl$ {
return 403;
}
location ~ ^/'.$rewrite_base.'/(.*).sql$ {
return 403;
}
location ~ /$ {
}
location ~ (.*)/$ {
}
autoindex off;
location /'.$rewrite_base.'/ {
if ($request_filename ~ favicon.ico){
rewrite ^/'.$rewrite_base.'/image\/(.+\.(jpg|gif|jpeg|png|bmp))$ /'.$rewrite_base.'/extensions/jit_image_manipulation/lib/image.php?param=$1 break;
}
if (!-e $request_filename){
rewrite ^/'.$rewrite_base.'/(.*)$ /'.$rewrite_base.'/$1/ redirect;
}
rewrite ^/'.$rewrite_base.'/(symphony/)?index.php(/.*/?) /'.$rewrite_base.'/$1$2;
if (!-e $request_filename){
rewrite ^/'.$rewrite_base.'/symphony(\/(.*\/?))?$ /'.$rewrite_base.'/index.php?symphony-page=$1&mode=administration&$query_string break;
}
if (!-e $request_filename){
rewrite ^/'.$rewrite_base.'/(.*\/?)$ /'.$rewrite_base.'/index.php?symphony-page=$1&$query_string break;
}
}
location /'.$rewrite_base.'/symphony {
rewrite ^/'.$rewrite_base.'/symphony\/?$ /'.$rewrite_base.'/index.php?mode=administration&$query_string break;
}
# nginx configuration
location ~ ^/manifest/(.*)$ {
return 403;
}
location ~ ^/workspace/utilities/(.*).xsl$ {
return 403;
}
location ~ ^/workspace/pages/(.*).xsl$ {
return 403;
}
location ~ ^/(.*).sql$ {
return 403;
}
location ~ (^|/)\. {
return 403;
}
location ~ /$ {
}
location ~ (.*)/$ {
}
autoindex off;
location / {
if ($request_filename ~ favicon.ico){
rewrite ^/image\/(.+\.(jpg|gif|jpeg|png|bmp))$ /extensions/jit_image_manipulation/lib/image.php?param=$1 break;
}
if (!-e $request_filename){
rewrite ^(.*)$ /$1/ redirect;
}
rewrite ^/(symphony/)?index.php(/.*/?) /$1$2;
if (!-e $request_filename){
rewrite ^/symphony(\/(.*\/?))?$ /index.php?symphony-page=$1&mode=administration&$query_string break;
}
if (!-e $request_filename){
rewrite ^/(.*\/?)$ /index.php?symphony-page=$1&$query_string break;
}
}
location /symphony {
rewrite ^/symphony\/?$ /index.php?mode=administration&$query_string break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment