Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On

############################################
# CORS: use "always" so headers are sent on errors/404; answer OPTIONS before routing
<IfModule mod_headers.c>
	Header always set Access-Control-Allow-Origin "*"
	Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
	Header always set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, languageID, WebsiteID, SubsiteID, X-User-Agent, Authorization, usertoken, userselectedshippingid"
</IfModule>

############################################
#Redirect to www.
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
#RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^(.*[^/])$ /$1/ [L,R=301] 

############################################

############################################
#Rewrite robots.txt to controller
RewriteRule  ^robots\.txt$ index.php?q=robots [L,QSA]
############################################

############################################
#Rewrite googleshopping.xml to controller
RewriteRule  ^googleshopping\.xml$ index.php?q=xmlfeed/googleshopping [L,QSA]
############################################


## never rewrite for existing files, directories and links

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

############################################
## Never rewrite for not existing js|css|jpg|gif|png|jpeg|swf

RewriteCond %{REQUEST_URI} !^(.*).(js|css|jpg|gif|png|jpeg|swf)$

############################################
## Rewrite all other requests to index.phpz

RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

############################################
## Deflate 

AddDefaultCharset UTF-8
<IfModule mod_deflate.c>
	SetOutputFilter DEFLATE
    AddOutPutFilterByType DEFLATE text/html text/plain text/xml text/css text/js text/javascript application/javascript
    <IfModule mod_setenvif.c>
        # Netscape 4.x has some problems...
        BrowserMatch ^Mozilla/4 gzip-only-text/html

        # Netscape 4.06-4.08 have some more problems
        BrowserMatch ^Mozilla/4\.0[678] no-gzip

        # MSIE masquerades as Netscape, but it is fine
        # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

        # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
        # the above regex won't work. You can use the following
        # workaround to get the desired effect:
        BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

        # Don't compress images
        SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
    </IfModule>

    <IfModule mod_headers.c>
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
	
</IfModule>


############################################
## Set expire header for static contents

ExpiresActive On
ExpiresDefault A0

# 1 WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
ExpiresDefault A604800
</FilesMatch>

# 1 WEEK
<FilesMatch "\.(txt|xml|js|ico|css)$">
ExpiresDefault A604800
</FilesMatch>

# 1 WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>

# 1 WEEK
<FilesMatch "\.(txt|xml|js|ico|css)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
## Disable PHP|Perl|Ruby in Uploads Folder
RewriteRule ^public/uploads/.*\.(php|rb|py)$ - [F,L,NC]

Header unset Upgrade