RewriteEngine On
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Redirect to www
RewriteCond %{REQUEST_URI} !robots\.txt$
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteRule .* http://www.%{HTTP_HOST}/$0 [R=301,L]
# Redirect urls with no trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/odminka/
RewriteCond %{REQUEST_URI} !^/guide
RewriteCond %{REQUEST_URI} !\.xml$
RewriteCond %{REQUEST_URI} !\.txt$
RewriteCond %{REQUEST_URI} !/$
RewriteRule .+ $0/ [R=301,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
AddDefaultCharset utf-8
server {
server_name test.ru;
rewrite ^ http://www.test.ru$request_uri? permanent;
}
server {
listen 80;
server_name www.test.ru;
root /sites/test_ru/public/www;
index index.php;
location ~* \.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|ico|css)$ {
expires max;
}
location / {
expires off;
try_files $uri $uri/ @kohana;
}
location ~* \.php$ {
try_files $uri $uri/ @kohana;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME /path/to/fastcgi_script_name;
include fastcgi_params;
}
location @kohana {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
include fastcgi_params;
}
}
server {
listen 80;
listen 443 ssl http2;
ssl_certificate /cert.crt;
ssl_certificate_key /key.key;
server_name www.example.com;
return 301 https://example.com$request_uri;
}
server {
listen 80;
listen 443 ssl http2;
ssl_certificate /cert.crt;
ssl_certificate_key /key.key;
server_name example.com;
index index.html index.htm index.php index.cgi index.pl index.xhtml;
location ~ /\. { internal; }
location / { rewrite ^([^.\?]*[^/])$ $1/ permanent; }
location /odminka/ { }
location /guide { }
try_files $uri $uri/ /index.php/$uri;
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
}