Nginx将所有请求从子目录重定向到另一个子目录根目录
我对Nginx很陌生,所以请忍受我。
我正在尝试将所有请求从一个子目录(存储)重定向到另一个子目录(trade)的根目录。请参阅下面的进度。目标子目录(trade)中的站点是洋红色站点,因此这是大多数当前规则的用途。
server {
server_name example.com *.example.com;
root /usr/share/nginx/html/example.com/public_html;
index index.php index.html index.htm;
access_log /var/log/nginx/example.access.log;
error_log /var/log/nginx/example.error.log;
location / {
try_files $uri $uri/ /index.html;
}
location /trade/ {
index index.html index.php;
try_files $uri $uri/ @handler;
expires 30d;
}
location ~ /store {
rewrite /trade permanent;
}
location ~ ^/trade/(app|includes|lib|media/downloadable|pkginfo|report/config.xml|var)/ { internal; }
location /trade/var/export/ { internal; }
location /. { return 404; }
location @handler { rewrite / /trade/index.php; }
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
我用于重定向的部分如下:
location ~ /store {
rewrite /trade permanent;
}
这适用于 example.com/store 但不适用于示例/存储/索引.php或任何其他带有 args 的 uri。我有一种感觉,底部的php文件部分正在覆盖处理。这就是为什么我把〜放在商店位置的前面,因为这里的文档指出这将首先处理。处理是停止还是继续?
我已经读过关于嵌套php规则的文章,但我尝试过这个无济于事。
我将不胜感激任何帮助。