Правильный .htaccess для Opencart
У каждого сайта обязательно должен быть файл конфигурации сервера, в котором можно задать различные настройки безопасности, переадресации, сжатия файлов и другое. Из-за не правильной настройки могут быть проблемы с сайтом от медленной работы и до полного отключения. Находится .htaccess в корневой папке сайта там же, где robots.txt и config.php. По-умолчанию после установки opencart этот файл есть, но он не работает и надо сделать ряд хитрых действий. Для настройки htaccess нужны определенные знания, но как вариант - скопировать уже готовый вариант, который найдете в интернете или на этой странице.
Примечание:
Название файла должно быть без расширения и с точкой вначале. Было так htaccess.txt -> стало так .htaccess
Внутри файла почти всегда есть строки с символом # - это комментарии, которые не влияют на работу и существуют для удобства веб-мастеров.
Содержимое .htaccess для Opencart
AddDefaultCharset UTF-8
RewriteEngine On
Options +SymLinksIfOwnerMatch
Options -Indexes
Order Allow,Deny
deny from all
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=extension/feed/sitemap_pro [L]
# RewriteRule ^sitemap.xml$ index.php?route=feed/fast_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\ HTTP/
RewriteRule ^index\.html$ / [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ / [R=301,L]
RewriteCond %{QUERY_STRING} ^route=common/home$
RewriteCond %{REQUEST_METHOD} !^POST$
RewriteRule ^index\.php$ https://%{HTTP_HOST}? [R=301,L]
RewriteCond %{REQUEST_URI} ^/index$ [OR]
RewriteCond %{REQUEST_URI} ^/index[.]+(\w+)$
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript