nginx - Nginx 忽略尾随斜杠,如果丢失不重定向
问题描述
使用我当前的配置,以下 URL 会触发对 SEO 非常不利的重定向。
http://localhost/blog 重定向到 -> http://localhost/blog/
这是我的 conf.d/default.conf 文件
server {
listen 80 default_server;
server_name localhost;
server_name_in_redirect on;
location / {
add_header Cache-Control "public";
expires 1y;
root /work/front-page/dist/browser;
}
}
我希望这两个位置都提供状态 200,或者至少要反转重定向
http://localhost/blog/重定向到 -> http://localhost/blog
编辑:把
try_files $uri $uri/index.html =404;
似乎解决了这个问题,谢谢@Richard Smith
这是完整的工作配置,我也使用 http -> https 重定向对其进行了测试。
server {
listen 80 default_server;
server_name localhost;
server_name_in_redirect on;
location / {
add_header Cache-Control "public";
expires 1y;
try_files $uri $uri/index.html =404;
root /work/front-page/dist/browser;
}
}
解决方案
推荐阅读
- c - 如何将字体设置为用户使用字体选择器选择的字体?
- php - 删除获取请求的 url .php 扩展名和参数?
- vue.js - Vue js如何使用props值到v-model
- nginx - 使用 nginx 反向代理丢失 POST 请求正文
- arrays - 如何将 json 数据显示到 laravel 刀片中?
- php - php sqlsrv 通过多台服务器连接到一个特定的数据库
- java - 如何通过 LLRP 从 EPC RFID 标签读取用户数据(内存)?
- typescript - 如何修复 no-unsafe-any 规则?
- ios - 如何在 Swift 中使用查询语句检索数据?
- elasticsearch - ElasticSearch 词袋字段匹配