【问题标题】:Redirect 301: how to convert from Nginx to Apache重定向 301:如何从 Nginx 转换为 Apache
【发布时间】:2018-11-04 18:34:56
【问题描述】:

我需要将网站从 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 规则吗?

【问题讨论】:

标签: regex apache nginx


【解决方案1】:

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

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]

【讨论】:

    猜你喜欢
    • 2021-05-19
    • 2016-08-31
    • 2020-10-29
    • 1970-01-01
    • 1970-01-01
    • 2013-05-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多