html - 使用 NGINX 从链接中删除 .html
问题描述
我的 nginx 站点可用文件有这个配置。它会创建一个链接,例如https://website.com/news-id.html
我想要做的是从链接中删除“news-”和 .html 并使用https://website.com/id使 url 干净
我尝试了几种方法,但每次遇到重定向循环。
**我尝试了几次将代码放在这里但失败了。所以这里是配置文件的链接https://jpst.it/1AKIf
解决方案
试试这个配置。
server {
location / {
# Redirects to the version without .html
if ($request_uri ~ ^/(.*)\.html$) { return 302 /$1; }
# Tries the uri, .html file and the news prefix.
try_files $uri $uri/ $uri.html news-$uri news-$uri/
}
}
推荐阅读
- python - 使用 Python/boto3 更新 S3 存储桶中的静态网页
- ruby-on-rails - 使用设计时在模型上自动设置 created_by
- reactjs - 如何在标头中传递授权令牌以响应 Axios.post?
- artifactory - 在虚拟或远程存储库的情况下,Artifactory 搜索 API 返回空列表
- powershell - 通过任务计划程序执行时,Powershell 脚本引发错误
- c - 我想从字符串中删除符号并反转字符串
- laravel - 在 Laravel 中为多模型使用图库图像
- json - 如何将null转换为空字符串?
- c++ - Know if CPU supports nanoseconds
- javascript - NodeJS 错误:无法 GET/ 在 Web 浏览器上运行 url