# Rule file .htaccess
RewriteEngine on
Options +FollowSymLinks
Options -indexes
AddDefaultCharset utf-8

<IfModule mod_rewrite.c>
	# Redirecting www
	# Configure if you want redirect url http://example.com to http://www.example.com
	RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
	RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L] 
	
	# Alias: If you have configured an alias in the httpd.conf of Apache
	# Uncomment this line and configure the name of your alias.
	# If you are not sure don't change this line.
	#RewriteBase /myAliasName/
	
	# Zone to define your URL rewriting
	# Exemple 1: 
	# Create an URL with 1 virtual folder (myfolder)
	# RewriteRule ^myfolder/(.+)\.html$ index.php?p=$1&l=en&folder_level=1&%{QUERY_STRING} [L] 
	# RewriteRule ^([a-z]{2})/myfolder/(.+)\.html$ index.php?p=$2&l=$1&folder_level=1&%{QUERY_STRING} [L] 
	# 
	# Exemple 2: 
	# Create an URL with 2 virtuals folders (myfolder and myfolder2)
	# RewriteRule ^myfolder/myfolder2/(.+)\.html$ index.php?p=$1&l=en&folder_level=2&%{QUERY_STRING} [L] 
	# RewriteRule ^([a-z]{2})/myfolder/myfolder2/(.+)\.html$ index.php?p=$2&l=$1&folder_level=2&%{QUERY_STRING} [L] 
	# 
	# Exemple 3: 
	# Create an URL with 1 variable virtual folder (warning param2)
	# RewriteRule ^([a-z]{2})/((?!(ajax|wsp\-admin)).+)/(.+)\.html$ index.php?p=my_page&l=$1&param1=$2&param2=$3&folder_level=1&%{QUERY_STRING} [L]
	# 
	# Warning: Create your rules only if the framework can't support your special URL => virtual folder (the framework manages the real folders)
	#
	
	# End zone for your URL rewriting (don't write anything after this line and don't remove it)
	
	
	# Google / Yahoo / Bing site verification
	RewriteRule ^google(.*).html$ google$1.html [L] 
	RewriteRule ^([a-z]{2})/google(.*).html$ google$2.html [L] 
	RewriteRule ^y_key_(.*).html$ y_key_$1.html [L] 
	RewriteRule ^([a-z]{2})/y_key_(.*).html$ y_key_$2.html [L] 
	RewriteRule ^LiveSearchSiteAuth.xml$ LiveSearchSiteAuth.xml [L] 
	RewriteRule ^([a-z]{2})/LiveSearchSiteAuth.xml$ LiveSearchSiteAuth.xml [L] 
	RewriteRule ^BingSiteAuth.xml$ BingSiteAuth.xml [L] 
	RewriteRule ^([a-z]{2})/BingSiteAuth.xml$ BingSiteAuth.xml [L] 
	
	# FrameWork Files
	RewriteRule ^robots.txt$ robots.txt [L] 
	RewriteRule ^([a-z]{2})/robots.txt$ robots.txt [L] 
	RewriteRule ^favicon.ico$ favicon.ico [L] 
	RewriteRule ^([a-z]{2})/favicon.ico$ favicon.ico [L] 
	RewriteRule ^wsp/includes/googlegeolocalisationsession.php(.*)$ wsp/includes/GoogleGeolocalisationSession.php$1 [L] 
	
	# JS /CSS combine
	RewriteRule ^wsp/includes/combine.php(.*)$ wsp/includes/combine.php$1 [L] 
	RewriteRule ^([a-z]{2})/wsp/includes/combine.php(.*)$ wsp/includes/combine.php$2 [L] 
	RewriteRule ^combine-js/(.*\.js) wsp/includes/combine.php?type=js&files=$1 [L] 
	RewriteRule ^wsp/includes/css-merge.php(.*)$ wsp/includes/css-merge.php$1 [L] 
	RewriteRule ^combine-css/(.*\.css) wsp/includes/combine.php?type=css&files=$1&%{QUERY_STRING} [L] 
	RewriteRule ^combine-css/wsp/(.*) wsp/$1&%{QUERY_STRING} [L] 
	
	# Banned files/folders of the FrameWork
	RewriteRule ^wsp/class/(.*)\.php$ index.php?p=error-page&error-redirect=404&banned_url=true&folder_level=2 [L] 
	RewriteRule ^wsp/config/(.*)\.php$ index.php?p=error-page&error-redirect=404&banned_url=true&folder_level=2 [L]
	RewriteRule ^wsp/includes/execution_time\.php$ index.php?p=error-page&error-redirect=404&banned_url=true&folder_level=2 [L] 
	RewriteRule ^wsp/includes/html2text\.inc\.php$ index.php?p=error-page&error-redirect=404&banned_url=true&folder_level=2 [L] 
	RewriteRule ^wsp/includes/init\.inc\.php$ index.php?p=error-page&error-redirect=404&banned_url=true&folder_level=2 [L] 
	RewriteRule ^wsp/includes/loader_(.*)\.inc\.php$ index.php?p=error-page&error-redirect=404&banned_url=true&folder_level=2 [L] 
	RewriteRule ^wsp/includes/utils_(.*)\.inc\.php$ index.php?p=error-page&error-redirect=404&banned_url=true&folder_level=2 [L] 
	RewriteRule ^wsp/includes/utils\.inc\.php$ index.php?p=error-page&error-redirect=404&banned_url=true&folder_level=2 [L] 
	RewriteRule ^wsp/includes/utils2\.inc\.php$ index.php?p=error-page&error-redirect=404&banned_url=true&folder_level=2 [L] 
	RewriteRule ^wsp/includes/wsp_user_ban\.inc\.php$ index.php?p=error-page&error-redirect=404&banned_url=true&folder_level=2 [L]
	
	# FrameWork Folders
	RewriteRule ^js/(.*)$ js/$1 [L] 
	RewriteRule ^wsp/js/(.*)$ wsp/js/$1 [L]
	RewriteRule ^css/(.*)$ css/$1 [L] 
	RewriteRule ^wsp/css/(.*)$ wsp/css/$1 [L] 
	RewriteRule ^wsp/includes/(.*)$ wsp/includes/$1 [L] 
	RewriteRule ^wsp/img/(.*)$ wsp/img/$1 [L] 
	RewriteRule ^([a-z]{2})/img/(.*)$ img/$2 [L] 
	RewriteRule ^img/(.*)$ img/$1 [L] 
	RewriteRule ^wsp/flash/(.*)$ wsp/flash/$1 [L] 
	RewriteRule ^([a-z]{2})/flash/(.*)$ flash/$2 [L] 
	RewriteRule ^flash/(.*)$ flash/$1 [L] 
	
	# Rewrite Ajax URL
	RewriteRule ^([a-z]{2})/ajax/(.+)/(.+)/(.+)/(.+)/(.+)/(.+)\.html$ index-ajax.php?p=$2/$3/$4/$5/$6/$7&l=$1&folder_level=6&%{QUERY_STRING} [L] 
	RewriteRule ^ajax/(.+)/(.+)/(.+)/(.+)/(.+)/(.+)\.html$ index-ajax.php?p=$1/$2/$3/$5/$6/$7&folder_level=6&%{QUERY_STRING} [L] 
	RewriteRule ^([a-z]{2})/ajax/(.+)/(.+)/(.+)/(.+)/(.+)\.html$ index-ajax.php?p=$2/$3/$4/$5/$6&l=$1&folder_level=5&%{QUERY_STRING} [L] 
	RewriteRule ^ajax/(.+)/(.+)/(.+)/(.+)/(.+)\.html$ index-ajax.php?p=$1/$2/$3/$5/$6&folder_level=5&%{QUERY_STRING} [L] 
	RewriteRule ^([a-z]{2})/ajax/(.+)/(.+)/(.+)/(.+)\.html$ index-ajax.php?p=$2/$3/$4/$5&l=$1&folder_level=4&%{QUERY_STRING} [L] 
	RewriteRule ^ajax/(.+)/(.+)/(.+)/(.+)\.html$ index-ajax.php?p=$1/$2/$3/$5&folder_level=4&%{QUERY_STRING} [L] 
	RewriteRule ^([a-z]{2})/ajax/(.+)/(.+)/(.+)\.html$ index-ajax.php?p=$2/$3/$4&l=$1&folder_level=3&%{QUERY_STRING} [L] 
	RewriteRule ^ajax/(.+)/(.+)/(.+)\.html$ index-ajax.php?p=$1/$2/$3&folder_level=3&%{QUERY_STRING} [L] 
	RewriteRule ^([a-z]{2})/ajax/(.+)/(.+)\.html$ index-ajax.php?p=$2/$3&l=$1&folder_level=2&%{QUERY_STRING} [L] 
	RewriteRule ^ajax/(.+)/(.+)\.html$ index-ajax.php?p=$1/$2&folder_level=2&%{QUERY_STRING} [L] 
	RewriteRule ^([a-z]{2})/ajax/(.+)\.html$ index-ajax.php?p=$2&l=$1&folder_level=1&%{QUERY_STRING} [L] 
	RewriteRule ^ajax/(.+)\.html$ index-ajax.php?p=$1&folder_level=1&%{QUERY_STRING} [L] 
	RewriteRule ^([a-z]{2})/ajax/$ index-ajax.php?p=home&l=$1&folder_level=1&%{QUERY_STRING} [L] 
	RewriteRule ^ajax/$ index-ajax.php?p=home&folder_level=1&%{QUERY_STRING} [L] 

	# Rewrite URL subfolder (ex: wsp-admin, ...)
	RewriteRule ^([a-z]{2})/(.+)/(.+)/(.+)/(.+)/(.+)/(.+)\.html$ index.php?p=$2/$3/$4/$5/$6/$7&l=$1&folder_level=5&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})(.+)/(.+)/(.+)/(.+)/(.+)/(.+)\.html$ index.php?p=$1$2/$3/$4/$5/$6/$7&folder_level=5&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})/(.+)/(.+)/(.+)/(.+)/(.+)/$ index.php?p=$2/$3/$4/$5/$6/home&l=$1&folder_level=5&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})/(.+)/(.+)/(.+)/(.+)/(.+)\.html$ index.php?p=$2/$3/$4/$5/$6&l=$1&folder_level=4&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})(.+)/(.+)/(.+)/(.+)/(.+)\.html$ index.php?p=$1$2/$3/$4/$5/$6&folder_level=4&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})/(.+)/(.+)/(.+)/(.+)/$ index.php?p=$2/$3/$4/$5/home&l=$1&folder_level=4&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})/(.+)/(.+)/(.+)/(.+)\.html$ index.php?p=$2/$3/$4/$5&l=$1&folder_level=3&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})(.+)/(.+)/(.+)/(.+)\.html$ index.php?p=$1$2/$3/$4/$5&folder_level=3&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})/(.+)/(.+)/(.+)/$ index.php?p=$2/$3/$4/home&l=$1&folder_level=3&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})/(.+)/(.+)/(.+)\.html$ index.php?p=$2/$3/$4&l=$1&folder_level=2&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})(.+)/(.+)/(.+)\.html$ index.php?p=$1$2/$3/$4&folder_level=2&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})/(.+)/(.+)/$ index.php?p=$2/$3/home&l=$1&folder_level=2&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})/(.+)/(.+)\.html$ index.php?p=$2/$3&l=$1&folder_level=1&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})(.+)/(.+)\.html$ index.php?p=$1$2/$3&folder_level=1&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})/(.+)/$ index.php?p=$2/home&l=$1&folder_level=1&%{QUERY_STRING} [L]

	# Rewrite Special URL subfolder (ex: xml, rss, sitemap, ...)
	RewriteRule ^([a-z]{2})/(.+)/(.+)/(.+)/(.+)/(.+)/(.+)\.([^php]+)$ load-page.php?p=$2/$3/$4/$5/$6/$7&mime=$6&l=$1&folder_level=5&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})(.+)/(.+)/(.+)/(.+)/(.+)/(.+)\.([^php]+)$ load-page.php?p=$1$2/$3/$4/$5/$6/$7&mime=$6&folder_level=5&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})/(.+)/(.+)/(.+)/(.+)/(.+)\.([^php]+)$ load-page.php?p=$2/$3/$4/$5/$6&mime=$6&l=$1&folder_level=4&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})(.+)/(.+)/(.+)/(.+)/(.+)\.([^php]+)$ load-page.php?p=$1$2/$3/$4/$5/$6&mime=$6&folder_level=4&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})/(.+)/(.+)/(.+)/(.+)\.([^php]+)$ load-page.php?p=$2/$3/$4/$5&mime=$6&l=$1&folder_level=3&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})(.+)/(.+)/(.+)/(.+)\.([^php]+)$ load-page.php?p=$1$2/$3/$4/$5&mime=$6&folder_level=3&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})/(.+)/(.+)/(.+)\.([^php]+)$ load-page.php?p=$2/$3/$4&mime=$5&l=$1&folder_level=2&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})(.+)/(.+)/(.+)\.([^php]+)$ load-page.php?p=$1$2/$3/$4&mime=$5&folder_level=2&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})/(.+)/(.+)\.([^php]+)$ load-page.php?p=$2/$3&mime=$4&l=$1&folder_level=1&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})(.+)/(.+)\.([^php]+)$ load-page.php?p=$1$2/$3&mime=$4&folder_level=1&%{QUERY_STRING} [L]
	RewriteRule ^([a-z]{2})/(.+)\.([^php]+)$ load-page.php?p=$2&l=$1&mime=$3&%{QUERY_STRING} [L]
	
	# Rewrite URL home.html, index.html and index.php
	RewriteRule ^([a-z]{2})/home.html$ /$1/ [R=301,L] 
	RewriteRule ^([a-z]{2})/home.html\?(.*)$ /$1/?$2 [R=301,L] 
	RewriteRule ^([a-z]{2})/index.html$ /$1/ [R=301,L] 
	RewriteRule ^([a-z]{2})/index.html\?(.*)$ /$1/?$2 [R=301,L] 
	RewriteRule ^([a-z]{2})/index.php$ /$1/ [R=301,L] 
	RewriteRule ^([a-z]{2})/index.php\?(.*)$ /$1/?$2 [R=301,L] 
	
	# Language rule
	RewriteRule ^([a-z]{2})$ index.php?l=$1&%{QUERY_STRING}
	RewriteRule ^([a-z]{2})/$ index.php?l=$1&%{QUERY_STRING}
	RewriteRule ^([a-z]{2})/(.+)\.html$ index.php?p=$2&l=$1&%{QUERY_STRING}
	RewriteRule ^(.+)\.html$ index.php?p=$1&%{QUERY_STRING}
	
	# Security
	RewriteRule ^lang/(.*)$ / [R=301,L] 
	RewriteRule ^pages/(.*)$ / [R=301,L] 
	RewriteRule ^wsp/(.*)$ / [R=301,L] 
	
	# ErrorDocument
	ErrorDocument 401 /error_doc.php?error=401
	ErrorDocument 403 /error_doc.php?error=403
	ErrorDocument 404 /error_doc.php?error=404
	ErrorDocument 500 /error_doc.php?error=500
</IfModule>


#####              Files Caching / Compression                  #####
#                                                                   #
# We recommand to activate Apache mod : mod_expires and mod_headers #
# Configure php.ini zlib.output_compression = On                    #
#                                                                   #
#####################################################################

<IfModule mod_headers.c>
	# Remote ETag from headers - http://www.askapache.com/htaccess/apache-speed-etags.html
	Header unset ETag
	# Disable ETag for files
	FileETag None
</IfModule>

<IfModule mod_expires.c>
	# Set up caching on media files for 1 month
	<FilesMatch "\.(ico|gif|jpg|jpeg|png|flv|pdf|swf|mov|mp3|wmv|ppt)$">
		ExpiresActive On
	  ExpiresDefault A2678400
	</FilesMatch>
	<FilesMatch "favicon\.ico$">
	  ExpiresActive On
	  ExpiresDefault A2678400
	</FilesMatch>
	
	# Set up 7 days caching on commonly updated files
	<FilesMatch "\.(xml|txt|js|css)$">
		ExpiresActive On
	  ExpiresDefault A604800
	</FilesMatch>
</IfModule>

<IfModule mod_headers.c>
	# Set up caching on media files for 1 month
	<FilesMatch "\.(ico|gif|jpg|jpeg|png|flv|pdf|swf|mov|mp3|wmv|ppt)$">
	  Header set Cache-Control "max-age=2678400, public"
	</FilesMatch>
	<FilesMatch "favicon\.ico$">
	  Header set Cache-Control "max-age=2678400, public"
	</FilesMatch>
	
	# Set up 7 days caching on commonly updated files
	<FilesMatch "\.(xml|txt|js|css)$">
	  Header set Cache-Control "max-age=604800, public, must-revalidate"
	</FilesMatch>
</IfModule>

<ifModule mod_deflate.c>
	<FilesMatch "\.(js|css|txt|xml|gif|jpg|jpeg|png)$">
		SetOutputFilter DEFLATE
	</FilesMatch>
</ifModule>
