codeigniter - Nginx 重写总是重定向
问题描述
我正试图通过这种重写example.com/a/a23uy324
来example.com/index.php/render?id=a23uy324
进行重写:
location ~ ^/a {
rewrite ^/a/(.*)$ https://example.com/index.php/render?id=$1 break;
}
但是任何规则,例如last
,break
或permanent
- 都不会产生任何影响。站点仍然重定向到 PHP 脚本。请指教。
这是完整的配置:
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name example.com www.example.com;
ssl_certificate /var/www/example.com/certificates/certificate.crt;
ssl_certificate_key /var/www/example.com/certificates/private.key;
root /var/www/example.com/public_html;
index index.php index.html index.htm;
#works
location ~ ^/a {
rewrite ^/a/(.*)$ https://example.com/index.php/render?id=$1 break;
}
location ~* ^/(assets|files|robots\.txt) { }
location / {
try_files $uri $uri/ /index.php?/$request_uri;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/example.com/public_html$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
expires 7d;
}
}
解决方案
推荐阅读
- java - 如何将 forEach 与可观察对象一起使用
- java - 从 AsyncTask 携带和重用信息(json 字符串)?
- elixir - 使用 HTTPoison 向 Plug 路由器发出的 POST 请求失败
- nginx - 使用 nginx 入口时是否有 pod 级别的 nginx?
- python - 在 Python 中将没有标点符号的印地语段落拆分成句子
- mysql - 在 mysql 数据库上查询后,Sequelize 模型不带 LONGTEXT 类型字段
- node.js - WebStorm 2018.1:我无法从 docker 容器运行远程调试打字稿时遇到断点
- google-apps-script - 使用应用程序脚本插入时单元格公式未更新
- ansible - Ansible win_audit_policy_system 模块不改变值
- python - Python Pandas 动态读取具有不同列大小的多个标题行的 Excel 表