regex - 重定向 301:如何从 Nginx 转换为 Apache
问题描述
我需要将网站从 Nginx Web 服务器移动到 Apache。除了与旧 URL 兼容所需的两条规则外,我成功地转换了所有内容(该网站以前是用 ASP 开发的,然后用 PHP 重写)。
这些规则是:
location /images/index.asp {
return 301 $scheme://$server_name/image-library?$args;
}
重定向请求它将对https://www.domain.ext/images/index.asp?var1=somevalue&var2=someother到https://www.domain.ext/image-library?var1=somevalue&var2=someother
和:
location ~ ^/images/(?<year>[0-9]+)/index.asp {
return 301 $scheme://$server_name/image-library?img_year=$year&$args;
}
它重定向对https://www.domain.ext/images/2018/index.asp?var1=somevalue&var2=someother的请求到https://www.domain.ext/image-library?img_year=2018&var1=somevalue&var2=someother
你能帮我写正确的 RedirectMatch 301 规则吗?
解决方案
...与此同时,我发现了一个适合我的解决方案:第一条规则可以翻译为:
RewriteRule ^/images/index.asp https://www.domain.ext/image-library [R=301,QSA]
第二个为:
RewriteRule ^/images/([0-9]+)/index.asp https://www.domain.ext/image-library?img_year=$1 [R=301,QSA]
推荐阅读
- angular - 带有参数的角度路由redirectTo
- typescript - Typescript 无法识别 d.ts 模块
- node.js - npm 错误!缺少脚本:开始
- asp.net-mvc - 在 ASP .NET Core 中动态添加控件
- c# - 在 WinForms C# 中绘制实心圆
- vba - 用标签替换斜体文本
- android - Androidcontacts2.db读取mimetypes列(不是数据表中的记录)
- javascript - 如何在打字稿中以通用方式扩展 3rd 方类?
- android - 在 Android 上使用 React-Native 使用 `file://` URI 从本地应用程序缓存中获取文件返回“意外的 url”
- swift - 用于具有多输入和多输出的游戏 AI 的 CoreML