为返回“ 404”并转到URL的第一个目录创建了重定向,例如:
foo.com.br/air/uknwfileerror
> foo.com.br/air
但这不适用于.php
扩展名
foo.com.br/air/uknwfileerror.php
> foo.com.br/air
listen *:443;
server_name portal-dev.foo.com.br ;
root /var/www/novo;
ssl_session_cache shared:SSL:20m;
ssl_session_timeout 20m;
resolver 1.1.1.1;
set $proxy_foops_https 'https://proxy-portal-dev-stg.foo.com.br';
set $proxy_foops_http 'http://proxy-portal-dev-stg.foo.com.br';
ssl on;
ssl_certificate /etc/nginx/ssl/wildcard.crt;
ssl_certificate_key /etc/nginx/ssl/wildcard.key;
access_log /var/log/nginx/dev.foo.com.br.ssl.access.log;
error_log /var/log/nginx/dev.foo.com.br.ssl.error.log;
error_page 404 = @notfound;
location @notfound {
rewrite ^/([\w-]*)/.* https://$server_name/$1/ permanent;
}
add_header Access-Control-Allow-Origin '$http_origin';
add_header Access-Control-Allow-Headers 'origin, x-requested-with, content-type';
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Credentials 'true';
location = /portal/{
rewrite ^ https://$server_name/ permanent;
}
location /portal/ {
index index.php index.html index.htm;
try_files $uri $uri/ /portal/index.php?$args;
}
location ~ wp-login\.php$ {
allow all;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location / {
location ~* \.(jpg|jpeg|gif|bmp|ico|png|css|js|swf|woff)$ {
expires 7d;
access_log off;
}
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
fastcgi_intercept_errors on;
}
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location /cas/ {
proxy_pass $proxy_foops_https;
proxy_set_header Host portal-dev.foo.com.br;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_set_header X_FORWARDED_PROTO https;
}
location /auth-service {
proxy_pass $proxy_foops_https;
proxy_set_header Host portal-dev.foo.com.br;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_set_header X_FORWARDED_PROTO https;
}
}
使用Curl -I
,我看到它返回301,网址为foo.com.br/air/uknwfileerror.php
,但是使用路径foo.com.br/air/uknwfileerror
,它仅返回200,我下载了主页。
预期的是,当输入路径404时,它还会返回键入的第一个块:
foo.com.br/air/uknwfileerror.php
> foo.com.br/air
foo.com.br/air/uknwfileerror
> foo.com.br/air