我有一个nginx的网站configuration,这是完美的redirect所有.html请求通过/index.php 。 但是它不会将test.php重写为/index.php ,而是会抛出一个404错误。
任何人都可以摆脱灯吗? 这是我的网站configuration:
server { listen 80 default_server; location / { root /srv/www/htdocs; index index.php; try_files $uri $uri/ /index.php; location ~* \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param HTTPS on; # <-- add this line fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/nginx/fastcgi_params; fastcgi_buffer_size 128k; fastcgi_buffers 256 4k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; } } }
任何帮助表示赞赏 – 我正在撕掉我的头发!
location ~* \.php$将匹配任何*.php并导致try_files返回它,无论它的存在(因此404)。 考虑使用重写,而不是!
当try_files指令直接放入服务器时,只有在没有位置匹配的情况下才会被评估,所以如果一个请求已经以.php结尾,它就不会生效。 解决这个问题的方法是添加一个try_files $uri /index.php =404; 里面的PHP位置。