我正在尝试设置一个特定的重定向来强制重定向到index.php(对于Laravel)一个特定的子目录,绕过现有的index.html。
我想要捕获的网址看起来像这个app / kit //?email =。在每个目录中都有一个index.html文件(出于某些商业原因,很难改变这个)
重定向似乎有效,但是当我在index.php中解析$ _SERVER时,我丢失了查询字符串。
我的Nginx配置如下所示:
server {
server_name somedomain.com;
root /home/www/preprod/current/public/;
rewrite_log on;
access_log /var/log/nginx/preprod-access.log;
error_log /var/log/nginx/preprod-error.log notice;
location ~* /kit/(.*)/index\.html {
error_log /var/log/nginx/preprod-kit-error.log debug;
try_files /index.php?$query_string /dev/null;
}
location / {
index index.php index.html;
try_files $uri $uri/ /index.php?$query_string;
client_max_body_size 0;
autoindex off;
allow all;
}
location ~ \.php$ {
error_log /var/log/nginx/preprod-php-error.log debug;
#try_files $uri =404;
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_intercept_errors off;
fastcgi_connect_timeout 300s;
fastcgi_read_timeout 15m;
fastcgi_send_timeout 600s;
fastcgi_keep_conn on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
client_max_body_size 0;
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
所有应用程序都可以正常工作,除了这个。
编辑1:snippets / fastcgi-php.conf
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;
# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
#fastcgi_index index.php;
include fastcgi.conf;
答案 0 :(得分:0)
我找到了一个解决方案,我使用了这个:
location ~* /kit/(.*)/(.*) {
error_log /var/log/nginx/preprod.adsconsole.com-kit-error.log debug;
rewrite /kit/(.*)/(.*) /index.php$is_args$args;
}
regexp显然可以更好地编写,但如果它可以帮助某人!