/ja -> /jp
/ja/ -> /jp/
/ja/page -> /jp/page
server {
rewrite ^/ja($|/.*) /jp$1 permanent;
RewriteCond %{THE_REQUEST} " /\?(search=songs&tags=\S+) "
RewriteRule ^ /search.html?%1 [R=301,L]
?%1
можно убрать.RewriteCond %{THE_REQUEST} " /\?search=songs&tags="
RewriteRule ^ /search.html [R=301,L]
RewriteCond %{QUERY_STRING} ^search=songs&tags=
RewriteRule ^$ /search.html [R=301,L]
RewriteCond %{QUERY_STRING} (^|&)search=songs($|&)
RewriteCond %{QUERY_STRING} (^|&)tags=[^&]+($|&)
RewriteRule ^$ /search.html [R=301,L]
$str = preg_replace('#<img[^>]+src="[^"]*?([^/"]+)\.gif"[^>]*>#i', ':$1', $str);
RewriteCond %{THE_REQUEST} ([^\s]*)\.php(\?[^\s]*)?
RewriteRule (.*) %1 [R=301,L]
/file1.php
и /folder/file2.php
RewriteCond %{REQUEST_URI} !^/file1\.php
RewriteCond %{REQUEST_URI} !^/folder/file2\.php
RewriteCond %{THE_REQUEST} ([^\s]*)\.php(\?[^\s]*)?
RewriteRule (.*) %1 [R=301,L]
Если alias используется внутри location’а, заданного регулярным выражением, то регулярное выражение должно содержать выделения, а сам alias — ссылки на эти выделения
location ~* ^/static/\d+/(.+\.css)$ {
alias /path/to/static/$1;
}
location ~* ^/(static)/\d+/(.+\.css)$ {
alias %hostdir%/$1/$2;
}
location ~* ^.+\.(css...
. root /www/pcl.col;
location / {
try_files $uri /index.php$is_args$args;
}
location /project-1 {
try_files $uri /project-1/index.php;
}
location /project-2 {
try_files $uri /project-2/index.php;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
/path?query
/path
, а GET параметры следует искать в $args.if ($request_uri ~ "/\?[a-z]{9}") {
return 403;
}
(?-s)^.*$(?<!html)\R?
^(?-s:(.*html$)|.*\R?)
$1
$text = preg_replace('/<a\s[^<>]*href="[^"]*\K\(/', '1', $text);
$text = preg_replace_callback(
'/<a\s[^<>]*href="\K[^"]+/',
function ($m) {
return str_replace('(', '1', $m[0]);
},
$text
);
RewriteEngine on
RewriteRule ^[^/]+\.php$ /links/$0 [L]
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/links/$0 -f
RewriteRule ^[^/]+\.php$ /links/$0 [L]
htaccess: ErrorDocument takes two arguments, Change responses for HTTP errors
ErrorDocument 403 " 'a' \"b\" "
ErrorDocument 403 ' \'a\' "b" '
ErrorDocument 404 /page404.php мне не подходит.
RewriteRule
как-то конфликтуют с этим правилом, то можно проверять с каким кодом было перенаправление и для 4xx 5xx делать исключение пуская в обход основных правил.RewriteCond %{ENV:REDIRECT_STATUS} ^[45]\d\d
RewriteRule ^ - [L]
/upload/file.jpg
попадает в location ~* ^/(upload|bitrix/images|bitrix/tmp)
. if
и добавление try_files
не даст нужного результата.location ~* ^/(upload|bitrix/images|bitrix/tmp) {
if ( $upstream_http_x_accel_redirect = '' ) {
expires 30d;
}
try_files $uri /bitrix/images/main/blank.gif;
}
if
или вместо try_files
использовать error_page
location ~* ^/(upload|bitrix/images|bitrix/tmp) {
if ( $upstream_http_x_accel_redirect = '' ) {
expires 30d;
}
error_page 404 =200 /bitrix/images/main/blank.gif;
}
design/img/file.jpg
совпадает с шаблоном ^([^/]+)/([^/]+)/([^/]+)/?$
RewriteCond %{REQUEST_FILENAME} !-f
относится только одному первому RewriteRule
.RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([^/]*)/?$ index.php?module=SectionView§ion_url=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?module=CategoryView§ion_url=$1&category_url=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?module=SubcategoryView§ion_url=$1&category_url=$2&subcategory_url=$3 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?module=SubcategoryView§ion_url=$1&category_url=$2&subcategory_url=$3&subsubcategory_url=$4 [L,QSA]
RewriteRule ^p/([^/]+)/?$ index.php?module=PageView&page_url=$1 [L,QSA]
RewriteRule ^id/([^/]+)/?$ index.php?module=RecordView&id=$1 [L,QSA]
RewriteRule ^/?$ index.php?module=MainView [L,QSA]
/dir/1
, а в try_files нужно передать только часть /dir/
.(/[a-z-]+/)
и в $1 получаем нужное значение.location ~ "^(/[a-z-]+/)(1\d|[1-9])$" {
index /category.php;
try_files $1/ =404;
}