首页 > 解决方案 > 重定向 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=someotherhttps://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 规则吗?

标签: regexapachenginx

解决方案


...与此同时,我发现了一个适合我的解决方案:第一条规则可以翻译为:

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]

推荐阅读