# Author: Cayman Sistemas
# Version: 1.2.1 - 14/11/2018

RewriteEngine on

# LIBERA ACCESS CONTROL ALLOW ORIGIN

	Header Set Access-Control-Allow-Origin *

# HTTPS

	#RewriteCond %{HTTP_HOST} !^localhost [NC]
	#RewriteCond %{HTTP_HOST} !^192 [NC]
	#RewriteCond %{HTTP_HOST} !^www\.localhost [NC]
	#RewriteCond %{HTTP_HOST} !^www\. [NC]
	#RewriteCond %{HTTP_HOST} !^painel [NC]
	#RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301]

	#RewriteCond %{HTTPS} !=on
	#RewriteCond %{HTTP_HOST} !^localhost [NC]
	#RewriteCond %{HTTP_HOST} !^192 [NC]
	#RewriteCond %{HTTP_HOST} !^www\.localhost [NC]
	#RewriteCond %{HTTP_HOST} !^painel [NC]
	#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# INTERNACIONALIZAÇÃO

    RewriteCond %{HTTP_HOST} !^dev [NC]
	RewriteRule ^([a-z]{2})\/?$ app/index.php?lingua=$1
    RewriteCond %{HTTP_HOST} !^dev [NC]
	RewriteRule ^([a-z]{2})\/([a-z,0-9,_,A-Z,:,=,-]+)?\/?([a-z,0-9,_,A-Z,:,=,-]+)?\/?([a-z,0-9,_,A-Z,:,=,-]+)?\/?([a-z,0-9,_,A-Z,:,=,-]+)?\/?([a-z,0-9,_,A-Z,:,=,-]+)?\/?$ app/index.php?lingua=$1&p=$2&setor=$3&pag=$4&qua=$5&qui=$6 [L]

    RewriteCond %{HTTP_HOST} ^dev [NC]
	RewriteRule ^([a-z]{2})\/?$ app-dev/index.php?lingua=$1
    RewriteCond %{HTTP_HOST} ^dev [NC]
	RewriteRule ^([a-z]{2})\/([a-z,0-9,_,A-Z,:,=,-]+)?\/?([a-z,0-9,_,A-Z,:,=,-]+)?\/?([a-z,0-9,_,A-Z,:,=,-]+)?\/?([a-z,0-9,_,A-Z,:,=,-]+)?\/?([a-z,0-9,_,A-Z,:,=,-]+)?\/?$ app-dev/index.php?lingua=$1&p=$2&setor=$3&pag=$4&qua=$5&qui=$6 [L]

# AWS S3

	RewriteRule ^arquivos\/arquivos\/http(.*?)$ http$1 [L]
	RewriteRule ^arquivos\/arquivos\/(.*?)$ https://bewayonline.s3.sa-east-1.amazonaws.com/arquivos/arquivos/$1 [L]

# VERIFICA SE O ARQUIVO EXISTE

	#RewriteCond %{CONTEXT_DOCUMENT_ROOT}/arquivos/fotos/thumbs$1/$4/$2\-$3\.$5 -f
	#RewriteRule ^thumbs([0-3]?)\/([0-9]+)\/([0-9]+)\/(.*?).([a-z,A-Z]{3,4})\/?$ arquivos/fotos/thumbs$1/$4/$2\-$3\.$5 [L]

# THUMBS
	
	RewriteRule ^thumbs([0-3]?)\/([0-9]+)\/([0-9]+)\/https:\/bewayonline.s3.sa-east-1.amazonaws.com\/arquivos\/fotos\/(.*?)\.svg$ https:\/\/bewayonline.s3.sa-east-1.amazonaws.com\/arquivos\/fotos\/$4.svg [L,R=301]

	RewriteRule ^thumbs([0-3]?)\/([0-9]+)\/([0-9]+)\/(.*?)\.([a-z,A-Z]{3,4})$ app/index.php?p=thumbs&w=$2&h=$3&imagem=$4.$5&tipo=$1 [L]
	RewriteRule ^thumbs([0-3]?)\/([0-9]+)\/([0-9]+)\/(.*?)$ app/index.php?p=thumbs&w=$2&h=$3&imagem=$4&tipo=$1 [L]

# CORRIGE A UTILIZAÇÃO DE PASTAS

    RewriteCond %{HTTP_HOST} !^dev [NC]
	RewriteRule ^css\/(.*?)\.(.*?)$ app/css/$1.$2
    RewriteCond %{HTTP_HOST} !^dev [NC]
	RewriteRule ^css\/(.*?)\/(.*?)\.(.*?)$ app/css/$1/$2.$3
    RewriteCond %{HTTP_HOST} !^dev [NC]
	RewriteRule ^css\/(.*?)\/(.*?)\/(.*?)\.(.*?)$ app/css/$1/$2/$3.$4

    RewriteCond %{HTTP_HOST} !^dev [NC]
	RewriteRule ^js\/(.*?)\.(.*?)$ app/js/$1.$2
    RewriteCond %{HTTP_HOST} !^dev [NC]
	RewriteRule ^js\/(.*?)\/(.*?)\.(.*?)$ app/js/$1/$2.$3
    RewriteCond %{HTTP_HOST} !^dev [NC]
	RewriteRule ^js\/(.*?)\/(.*?)\/(.*?)\.(.*?)$ app/js/$1/$2/$3.$4

    RewriteCond %{HTTP_HOST} !^dev [NC]
	RewriteRule ^imagens\/(.*?)\.(.*?)$ app/imagens/$1.$2
    RewriteCond %{HTTP_HOST} !^dev [NC]
	RewriteRule ^imagens\/(.*?)\/(.*?)\.(.*?)$ app/imagens/$1/$2.$3
    RewriteCond %{HTTP_HOST} !^dev [NC]
	RewriteRule ^imagens\/(.*?)\/(.*?)\/(.*?)\.(.*?)$ app/imagens/$1/$2/$3.$4

    RewriteCond %{HTTP_HOST} ^dev [NC]
	RewriteRule ^css\/(.*?)\.(.*?)$ app-dev/css/$1.$2
    RewriteCond %{HTTP_HOST} ^dev [NC]
	RewriteRule ^css\/(.*?)\/(.*?)\.(.*?)$ app-dev/css/$1/$2.$3
    RewriteCond %{HTTP_HOST} ^dev [NC]
	RewriteRule ^css\/(.*?)\/(.*?)\/(.*?)\.(.*?)$ app-dev/css/$1/$2/$3.$4

    RewriteCond %{HTTP_HOST} ^dev [NC]
	RewriteRule ^js\/(.*?)\.(.*?)$ app-dev/js/$1.$2
    RewriteCond %{HTTP_HOST} ^dev [NC]
	RewriteRule ^js\/(.*?)\/(.*?)\.(.*?)$ app-dev/js/$1/$2.$3
    RewriteCond %{HTTP_HOST} ^dev [NC]
	RewriteRule ^js\/(.*?)\/(.*?)\/(.*?)\.(.*?)$ app-dev/js/$1/$2/$3.$4

    RewriteCond %{HTTP_HOST} ^dev [NC]
	RewriteRule ^imagens\/(.*?)\.(.*?)$ app-dev/imagens/$1.$2
    RewriteCond %{HTTP_HOST} ^dev [NC]
	RewriteRule ^imagens\/(.*?)\/(.*?)\.(.*?)$ app-dev/imagens/$1/$2.$3
    RewriteCond %{HTTP_HOST} ^dev [NC]
	RewriteRule ^imagens\/(.*?)\/(.*?)\/(.*?)\.(.*?)$ app-dev/imagens/$1/$2/$3.$4

# URL AMIGÁVEL

    RewriteCond %{HTTP_HOST} !^dev [NC]
    RewriteRule ^_ext - [L]
    RewriteCond %{HTTP_HOST} !^dev [NC]
	RewriteRule ^\/?$ app/index.php?lingua=br [L]
    RewriteCond %{HTTP_HOST} !^dev [NC]
	RewriteRule ^index\.php(.*)?$ app/index.php$1 [L]
    RewriteCond %{HTTP_HOST} !^dev [NC]
	RewriteRule ^([a-z,0-9,_,A-Z,:,=,-]+)\/?([a-z,0-9,_,A-Z,:,=,-]+)?\/?([a-z,0-9,_,A-Z,:,=,-]+)?\/?([a-z,0-9,_,A-Z,:,=,-]+)?\/?([a-z,0-9,_,A-Z,:,=,-]+)?\/?$ index.php?p=$1&setor=$2&pag=$3&qua=$4&qui=$5&email=$6&senha=$7&idUsuario=$8&lingua=br [QSA]

    RewriteCond %{HTTP_HOST} ^dev [NC]
	RewriteRule ^_ext - [L]
    RewriteCond %{HTTP_HOST} ^dev [NC]
	RewriteRule ^\/?$ app-dev/index.php?lingua=br
    RewriteCond %{HTTP_HOST} ^dev [NC]
	RewriteRule ^index\.php(.*)?$ app-dev/index.php$1
    RewriteCond %{HTTP_HOST} ^dev [NC]
	RewriteRule ^([a-z,0-9,_,A-Z,:,=,-]+)\/?([a-z,0-9,_,A-Z,:,=,-]+)?\/?([a-z,0-9,_,A-Z,:,=,-]+)?\/?([a-z,0-9,_,A-Z,:,=,-]+)?\/?([a-z,0-9,_,A-Z,:,=,-]+)?\/?$ app-dev/index.php?p=$1&setor=$2&pag=$3&qua=$4&qui=$5&lingua=br [L]

# FORÇA A UTILIZAR CACHE-CONTROL E EXPIRES HEADER

	<IfModule mod_headers.c>
	  Header unset ETag
	</IfModule>
	FileETag None
	<IfModule mod_expires.c>
	 ExpiresActive on
	 ExpiresDefault "access plus 1 month"
	 ExpiresByType text/cache-manifest "access plus 0 seconds"
	 # Html
	 ExpiresByType text/html "access plus 0 seconds"
	 # Data
	 ExpiresByType text/xml "access plus 0 seconds"
	 ExpiresByType application/xml "access plus 0 seconds"
	 ExpiresByType application/json "access plus 0 seconds"
	 # Feed
	 ExpiresByType application/rss+xml "access plus 1 hour"
	 ExpiresByType application/atom+xml "access plus 1 hour"
	 # Favicon
	 ExpiresByType image/x-icon "access plus 1 week"
	 # Media: images, video, audio
	 ExpiresByType image/gif "access plus 1 month"
	 ExpiresByType image/png "access plus 1 month"
	 ExpiresByType image/jpg "access plus 1 month"
	 ExpiresByType image/jpeg "access plus 1 month"
	 ExpiresByType video/ogg "access plus 1 month"
	 ExpiresByType audio/ogg "access plus 1 month"
	 ExpiresByType video/mp4 "access plus 1 month"
	 ExpiresByType video/webm "access plus 1 month"
	 # HTC files
	 ExpiresByType text/x-component "access plus 1 month"
	 # Webfonts
	 ExpiresByType application/x-font-ttf "access plus 1 month"
	 ExpiresByType font/opentype "access plus 1 month"
	 ExpiresByType application/x-font-woff "access plus 1 month"
	 ExpiresByType image/svg+xml "access plus 1 month"
	 ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
	 # CSS / JS
	 ExpiresByType text/css "access plus 1 year"
	 ExpiresByType application/javascript "access plus 1 year"
	 ExpiresByType application/x-javascript  "access plus 1 year"
	</IfModule>
	#Força o IE a sempre carregar utilizando a última versão disponível
	<IfModule mod_headers.c>
	  Header set X-UA-Compatible "IE=Edge"
	  <FilesMatch "\.(js|css|gif|png|jpeg|pdf|xml|oga|ogg|m4a|ogv|mp4|m4v|webm|svg|svgz|eot|ttf|otf|woff|ico|webp|appcache|manifest|htc|crx|oex|xpi|safariextz|vcf)$" >
	    Header unset X-UA-Compatible
	  </FilesMatch>
	</IfModule>

# GZIP

	<ifmodule mod_gzip.c="">
		mod_gzip_on       Yes
		mod_gzip_dechunk  Yes
		mod_gzip_item_include file      \.(html?|css|js|php|pl)$
		mod_gzip_item_include handler   ^cgi-script$
		mod_gzip_item_include mime      ^text/.*
		mod_gzip_item_include mime      ^application/x-javascript.*
		mod_gzip_item_exclude mime      ^image/.*
		mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
	</ifmodule>

# Força a utilizar Cache-Control e Expires header

	<IfModule mod_headers.c>
	Header unset ETag
	</IfModule>
	FileETag None
	<IfModule mod_expires.c>
	ExpiresActive on
	ExpiresDefault "access plus 1 month"
	ExpiresByType text/cache-manifest "access plus 0 seconds"

# Html

	ExpiresByType text/html "access plus 0 seconds"

# Data

	ExpiresByType text/xml "access plus 0 seconds"
	ExpiresByType application/xml "access plus 0 seconds"
	ExpiresByType application/json "access plus 0 seconds"

# Feed

	ExpiresByType application/rss+xml "access plus 1 hour"
	ExpiresByType application/atom+xml "access plus 1 hour"

# Favicon

	ExpiresByType image/x-icon "access plus 1 week"

# Media: images, video, audio

	ExpiresByType image/gif "access plus 1 month"
	ExpiresByType image/png "access plus 1 month"
	ExpiresByType image/jpg "access plus 1 month"
	ExpiresByType image/jpeg "access plus 1 month"
	ExpiresByType video/ogg "access plus 1 month"
	ExpiresByType audio/ogg "access plus 1 month"
	ExpiresByType video/mp4 "access plus 1 month"
	ExpiresByType video/webm "access plus 1 month"

# HTC files

	ExpiresByType text/x-component "access plus 1 month"

# Webfonts

	ExpiresByType application/x-font-ttf "access plus 1 month"
	ExpiresByType font/opentype "access plus 1 month"
	ExpiresByType application/x-font-woff "access plus 1 month"
	ExpiresByType image/svg+xml "access plus 1 month"
	ExpiresByType application/vnd.ms-fontobject "access plus 1 month"

# CSS / JS

	ExpiresByType text/css "access plus 1 year"
	ExpiresByType application/javascript "access plus 1 year"
	ExpiresByType application/x-javascript  "access plus 1 year"
	</IfModule>

# Força o IE a sempre carregar utilizando a última versão disponível

	<IfModule mod_headers.c>
	Header set X-UA-Compatible "IE=Edge"
	<FilesMatch "\.(js|css|gif|png|jpeg|pdf|xml|oga|ogg|m4a|ogv|mp4|m4v|webm|svg|svgz|eot|ttf|otf|woff|ico|webp|appcache|manifest|htc|crx|oex|xpi|safariextz|vcf)$" >
	Header unset X-UA-Compatible
	</FilesMatch>
	</IfModule>
	
##### LOCAWEB - NAO REMOVER #####
AddHandler php74-script .php
suPHP_ConfigPath /home/zsystem/public_html/_app_painel/
##### LOCAWEB - NAO REMOVER #####
