我必须删除一个子目录,该子目录已经复制在我的站点的几个URL中,通过永久重定向301。
我需要在Nginx配置方面的帮助。
例如:http://example.com/foo/DIR/DIR/bar -> http://example.com/foo/DIR/bar
location ~ ^(.*)/DIR/DIR(.*)$ {
rewrite ^(.*)$ /DIR/$1 last;
break;
}我当前的nginx服务器配置:
server {
listen 443 ssl http2 fastopen=500 reuseport;
listen [::]:443 ssl http2 fastopen=500 reuseport ipv6only=on;
server_name www.example.com;
resolver 1.1.1.1 1.0.0.1 valid=300s;
charset utf-8;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
include /etc/nginx/snippets/diffie-hellman;
root /var/www/webdisk/example.com/htdocs;
autoindex off;
index load.php index.php index.html;
include /etc/nginx/snippets/security;
include /etc/nginx/snippets/expires;
include /etc/nginx/snippets/error_pages;
include /etc/nginx/snippets/pagespeed;
location ~ \.php$ {
include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:/run/php/php7-fpm.sock;
fastcgi_send_timeout 1200s;
fastcgi_read_timeout 1200s;
fastcgi_connect_timeout 75s;
}
# TODO: http://example.com/foo/DIR/DIR/bar --> http://example.com/foo/DIR/bar
location ~* ^/(.+)$ {
if (-f $document_root/public/prov/$1.html) {
rewrite ^(.+)$ /public/prov/$1.html last;
break;
}
if (!-e $request_filename){
rewrite ^(.+)$ /load.php?request=$1 last;
break;
}
}
}我希望你能帮我,了解这种重定向应该怎么做。
在重定向之后,它必须按照PHP框架的最新指令进行处理。/load.php?request=$1
谢谢。
发布于 2019-01-24 12:30:51
要使用301响应重定向,需要使用rewrite...permanent或return 301 ...。
要删除URI的一部分,需要在要删除的部分之前和之后捕获URI的这些部分--就像location语句中的正则表达式一样。
例如:
rewrite ^(.*)/DIR/DIR(.*)$ $1/DIR$2 permanent;详情请参见本文件。
https://serverfault.com/questions/950429
复制相似问题