AddDefaultCharset UTF-8
ErrorDocument 404 /404
ErrorDocument 401 /password.php
RewriteEngine on

php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off

php_value memory_limit 128M

RewriteCond %{THE_REQUEST} //
   # Проверяем, повторяется ли слеш (//) более двух раз.
RewriteCond %{QUERY_STRING} !http(s|)://
  # Убедимся что это не урл в  GET
RewriteRule .* /$0 [R=301,L]
   # Исключаем все лишние слеши.

RewriteCond %{HTTPS} off
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_URI} !(.*)/$
#RewriteRule ^(.*[^/])$ $1/ [L,R=301]

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

RewriteCond %{HTTP_HOST} !atomicgarage\.ru [NC]
RewriteRule ^(.*)$ https://atomicgarage.ru/$1 [L,R=301]

RewriteRule ^index.html$	/ [L,R=301]

RewriteRule ^aktsii/(.*)$	/actions/$1 [L,R=301]


#RewriteRule ^sitemap/?$	site_map.php [L,QSA]
# RewriteRule ^/nashi-raboty/mercedes-benz/cls%d0%ba%d0%bb%d0%b0%d1%81%d1%81/$ /nashi-raboty/mercedes-benz/clsclass/ [L,R=301]
RewriteRule ^nashi-raboty/mercedes-benz/clsкласс/$ /nashi-raboty/mercedes-benz/clsclass/ [L,R=301]
RewriteRule ^nashi-raboty/mercedes-benz/claкласс/$ /nashi-raboty/mercedes-benz/claclass/ [L,R=301]
RewriteRule ^catalog/angelskie-glazki-na-mazda/mazda/$ /catalog/angelskie-glazki-na-mazda/ [L,R=301]
RewriteRule ^catalog/angelskie-glazki-na-renault/renault/$ /catalog/angelskie-glazki-na-renault/ [L,R=301]
RewriteRule ^catalog/angelskie-glazki-na-volkswagen/volkswagen/$ /catalog/angelskie-glazki-na-volkswagen/ [L,R=301]
RewriteRule ^catalog/shtatnye-hodovye-ogni-volkswagen/volkswagen/$ /catalog/shtatnye-hodovye-ogni-volkswagen/ [L,R=301]
RewriteRule ^catalog/shtatnye-hodovye-ogni-renault/renault/$ /catalog/shtatnye-hodovye-ogni-renault/ [L,R=301]
RewriteRule ^catalog/shtatnye-hodovye-ogni-hyundai/hyundai/$ /catalog/shtatnye-hodovye-ogni-hyundai/ [L,R=301]
RewriteRule ^catalog/shtatnye-hodovye-ogni-audi/AUDI/$ /catalog/shtatnye-hodovye-ogni-audi/ [L,R=301]
RewriteRule ^catalog/shtatnye-hodovye-ogni-mazda/mazda/$ /catalog/shtatnye-hodovye-ogni-mazda/ [L,R=301]
RewriteRule ^catalog/shtatnye-hodovye-ogni-mercedes-benz/mercedes-benz/$ /catalog/shtatnye-hodovye-ogni-mercedes-benz/ [L,R=301]
RewriteRule ^catalog/shtatnye-hodovye-ogni-toyota/toyota/$ /catalog/shtatnye-hodovye-ogni-toyota/ [L,R=301]
RewriteRule ^catalog/biksenonovye-linzy/AUDI/$ /catalog/biksenonovye-linzy/ [L,R=301]
RewriteRule ^catalog/nakladki-na-porogi-metallicheskie-kia/kia/$ /catalog/nakladki-na-porogi-metallicheskie-kia/ [L,R=301]
RewriteRule ^catalog/nakladki-na-porogi-s-podsvetkoj-citroen/citroen/$ /catalog/nakladki-na-porogi-s-podsvetkoj-citroen/ [L,R=301]
RewriteRule ^catalog/angelskie-glazki-na-subaru/subaru/$ /catalog/angelskie-glazki-na-subaru/ [L,R=301]
RewriteRule ^catalog/nakladki-na-porogi-s-podsvetkoj-opel/opel/$ /catalog/nakladki-na-porogi-s-podsvetkoj-opel/ [L,R=301]
RewriteRule ^articles/tehinfo/shtatnye-dnevnye-hodovye-ogni/$ /tehinfo/shtatnye-dnevnye-hodovye-ogni/ [L,R=301]
RewriteRule ^tehinfo/ustranenie-zapotevaniya-far/$ /tehinfo/poteet-fara/ [L,R=301]
RewriteRule ^article/catalog/dopolnitelnoe-oborudovanie/$ /catalog/dopolnitelnoe-oborudovanie/ [L,R=301]
RewriteRule ^brendy/$ /brands/ [L,R=301]

RewriteRule ^products/page-([0-9]+)/$ /products/?page=$1 [L,QSA]
RewriteRule ^brands/(.*)/page-(.*)/$ /brands/$1/?page=$2 [L,QSA]
RewriteRule ^catalog/(.*)/page-(.*)/$ /catalog/$1/?page=$2 [L,QSA]
RewriteRule ^otzyvy/page-(.*)/$ /otzyvy/?page=$1 [L,QSA]
RewriteRule ^articles/(.*)/page-(.*)/$ /articles/$1/?page=$2 [L,QSA]

# Каталог товаров
RewriteRule ^catalog/([^/]+)/?$	index.php?module=ProductsView&category=$1 [L,QSA]
RewriteRule ^catalog/([^/]+)/([^/]+)/?$	index.php?module=ProductsView&category=$1&brand=$2 [L,QSA]

RewriteRule ^products/([^/]+)/?$	index.php?module=ProductView&product_url=$1 [L,QSA]
RewriteRule ^products/?$	index.php?module=ProductsView [L,QSA]

RewriteRule ^brands/([^/]+)/?$	index.php?module=ProductsView&brand=$1 [L,QSA]
RewriteRule ^brands/([^/]+)/page_([^/]+)/?$	index.php?module=ProductsView&brand=$1&page=$2 [L,QSA]

# Поиск товаров
#RewriteRule ^search/([^/]+)/?$	index.php?module=ProductsView&keyword=$1 [L,QSA]
#RewriteRule ^search/?$	index.php?module=ProductsView [L,QSA]
RewriteRule ^search/([^/]+)/?$	index.php?module=SearchView&keyword=$1 [L,QSA]
RewriteRule ^search/?$	index.php?module=SearchView [L,QSA]

# Блог
RewriteRule ^actions/([^/]+)/?$	index.php?module=ActionsView&url=$1 [L,QSA]
RewriteRule ^actions/?$	index.php?module=ActionsView [L,QSA]

RewriteRule blog/([^/]+)/?$	/tehinfo/$1 [L,R=301]

RewriteRule ^tehinfo/([^/]+)/?$	index.php?module=BlogView&url=$1 [L,QSA]
RewriteRule ^tehinfo/?$	index.php?module=BlogView [L,QSA]



# Статьи
#RewriteRule ^articles/([^/]+)/?$    index.php?module=ArticlesView&category=$1 [L,QSA]
#RewriteRule ^articles/?$    index.php?module=ArticlesView [L,QSA]
#RewriteRule ^article/([^/]+)/?$    index.php?module=ArticlesView&article_url=$1 [L,QSA]

RewriteRule ^nashi-raboty/nashi-raboty/?$    /nashi-raboty/ [L,R=301]
RewriteRule ^articles/nashi-raboty/?$    /nashi-raboty/ [L,R=301]
RewriteRule ^article/([^/]+)/?$    /nashi-raboty/$1/ [L,R=301]
RewriteRule ^articles/([^/]+)/?$    /nashi-raboty/$1/ [L,R=301]


RewriteRule ^nashi-raboty/?$    index.php?module=ArticlesView&url=nashi-raboty [L,QSA]
RewriteRule ^nashi-raboty/page-([0-9]+)/?$    index.php?module=ArticlesView&url=nashi-raboty&page=$1 [L,QSA]

RewriteRule ^nashi-raboty/filter-([^/]+)/page-([0-9]+)/?$    index.php?module=ArticlesView&url=nashi-raboty&filter=$1&page=$2 [L,QSA]
RewriteRule ^nashi-raboty/filter-([^/]+)/?$    index.php?module=ArticlesView&url=nashi-raboty&filter=$1 [L,QSA]



RewriteRule ^nashi-raboty/([^/]+)/?$    index.php?module=ArticlesView&url=$1 [L,QSA]
RewriteRule ^nashi-raboty/([^/]+)/filter-([^/]+)/?$    index.php?module=ArticlesView&url=$1&filter=$2 [L,QSA]

RewriteRule ^nashi-raboty/([^/]+)/([^/]+)/?$    index.php?module=ArticlesView&url=$1&model=$2 [L,QSA]
RewriteRule ^nashi-raboty/([^/]+)/([^/]+)/filter-([^/]+)/?$    index.php?module=ArticlesView&url=$1&model=$2&filter=$3 [L,QSA]



# Услуги
RewriteRule ^tuning-centr/tuning-centr/?$    /tuning-centr/ [L,R=301]
RewriteRule ^tuning-centr/.+/([^/]+)/?$	index.php?module=PageView&page_url=$1 [L,QSA]
RewriteRule ^tuning-centr/([^/]+)/?$	index.php?module=PageView&page_url=$1 [L,QSA]
RewriteRule ^tuning-centr/?$	index.php?module=PageView&page_url=tuning-centr [L,QSA]

# Страницы
RewriteRule ^pages/.+/([^/]+)/?$	index.php?module=PageView&page_url=$1 [L,QSA]
RewriteRule ^pages/([^/]+)/?$	index.php?module=PageView&page_url=$1 [L,QSA]
RewriteRule ^pages/?$	index.php?module=PageView&page_url=$1 [L,QSA]

# Корзина и заказы
RewriteRule ^cart/?$	index.php?module=CartView   [L,QSA]
RewriteRule ^cart/([^/]+)/?$	index.php?module=CartView&add_variant=$1  [L,QSA]
RewriteRule ^cart/remove/([^/]+)/?$	index.php?module=CartView&delete_variant=$1  [L,QSA]
RewriteRule ^order/([^/]+)/?$	index.php?module=OrderView&url=$1  [L,QSA]
RewriteRule ^order/?$	index.php?module=OrderView  [L,QSA]

# Для пользователей
RewriteRule ^user/login/?$	index.php?module=LoginView  [L,QSA]
RewriteRule ^user/register/?$	index.php?module=RegisterView  [L,QSA]
RewriteRule ^user/logout/?$	index.php?module=LoginView&action=logout  [L,QSA]
RewriteRule ^user/password_remind/?$	index.php?module=LoginView&action=password_remind  [L,QSA]
RewriteRule ^user/password_remind/([0-9a-z]+)/?$	index.php?module=LoginView&action=password_remind&code=$1  [L,QSA]
RewriteRule ^user/?$	index.php?module=UserView  [L,QSA]

# Google sitemap
RewriteRule ^sitemap.xml?$	sitemap.php  [L,QSA]

# XML
RewriteRule ^yandex.yml?$	yandex.php  [L,QSA]

# feedback
# RewriteRule ^contact/?$    index.php?module=FeedbackView  [L,QSA]

# rss
RewriteRule ^rss/?$	index.php?module=RssView  [L,QSA]

#downloads
RewriteRule ^order/([^/]+)/([^/]+)/?$	index.php?module=OrderView&url=$1&file=$2  [L,QSA]

# Статические страницы
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$	index.php?module=PageView&page_url=$1 [L,QSA]
RewriteRule ^/?$	index.php?module=MainView&page_url= [L,QSA]

# Ресайз картинок на лету
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f


#RewriteCond %{THE_REQUEST} ^GET\ (.*)files/products/(.*)\?([A-z0-9]*)
#RewriteRule ^files/products/(.+) resize/resize.php?file=%2&token=%3 [L,NE]

RewriteRule ^files/products/(.+) resize/resize.php?file=$1&token=%{QUERY_STRING}
RewriteRule ^files/post/(.+) resize/resizepost.php?file=$1&token=%{QUERY_STRING}


#RewriteRule ^files/page/(.+) resize/resizepage.php?file=$1&token=%{QUERY_STRING}
RewriteRule ^files/page/(.+) resize/resizepage.php?file=$1&%{QUERY_STRING}

#RewriteRule ^files/categories/([0-9]+)x([0-9]+)/(.+) resize/resizecat.php?w=$1&h=$2&file=$3
#RewriteRule ^files/categories/(.+) resize/resizecat.php?file=$1&%{QUERY_STRING}

RewriteRule ^files/brands/(.+) resize/resize_brands.php?file=$1&token=%{QUERY_STRING}



# Включаем кэш в браузерах посетителей
<ifModule mod_headers.c>
    # Все html и htm файлы будут храниться в кэше браузера один день
    <FilesMatch "\.(html|htm)$">
       # Header set Cache-Control "max-age=60"
    </FilesMatch>
    # Все css, javascript и текстовые файлы будут храниться в кэше браузера одну неделю one year
    <FilesMatch "\.(js|css|txt)$">
        #Header set Cache-Control "max-age=604800"
        Header set Cache-Control "max-age=31536000"
    </FilesMatch>
    # Все флэш файлы и изображения будут храниться в кэше браузера один year
    <FilesMatch "\.(flv|swf|ico|gif|jpg|jpeg|png|otf|woff2)$">
        Header set Cache-Control "max-age=31536000"
    </FilesMatch>
    # Отключаем кеширование php и других служебных файлов
    <FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
        Header unset Cache-Control
    </FilesMatch>
</IfModule>

<ifModule mod_expires.c>
    ExpiresActive On
    #по умолчанию кеш в 5 секунд
    ExpiresDefault "access plus 5 seconds"
    # Включаем кэширование изображений и флэш на месяц
    
    ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
	ExpiresByType application/x-font-ttf "access plus 1 year"
	ExpiresByType application/x-font-opentype "access plus 1 year"
	ExpiresByType application/x-font-woff "access plus 1 year"
    
    
    ExpiresByType image/x-icon "access plus 1 month"
    ExpiresByType image/jpeg "access plus 4 weeks"
    ExpiresByType image/png "access plus 30 days"
    ExpiresByType image/gif "access plus 43829 minutes"
    ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
    # Включаем кэширование css, javascript и текстовых файлоф на одну неделю
    ExpiresByType text/css "access plus 604800 seconds"
    ExpiresByType text/javascript "access plus 604800 seconds"
    ExpiresByType application/javascript "access plus 604800 seconds"
    ExpiresByType application/x-javascript "access plus 604800 seconds"
    # Включаем кэширование html и htm файлов на один день
    #ExpiresByType text/html "access plus 60 seconds"
    # Включаем кэширование xml файлов на десять минут
    ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>


<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
</ifModule>

#Redirect url
Redirect 301 /products/biksenonovye-linzy-hella-evox-r/ https://atomicgarage.ru/catalog/biksenonovye-linzy-hella/