【问题标题】:Rewrite rule challenge in nginx在 nginx 中重写规则挑战
【发布时间】:2012-07-11 14:32:18
【问题描述】:

我有我们以前网站的旧网址

http://site.com/fixed-word/changing-category/12345-title-of-story

“变量”在哪里

不断变化的类别:例如体育、政治等

12345-title-of-story:12345 是旧的 id,其余的是故事 slug/title

新网站仅使用这种格式的故事片段

http://site.com/another-fixed-word/title-of-story

是否可以在nginx中创建301重写规则来实现?

我试过了:

重写 ^/fixed-word/([^\?]+)$/([^\?]+)$ /index.php?tipo=old_article&slug=$1 last;

想法是在 php 中获取 slug 并从 slug (12345-) 中删除数字 id 但不起作用,老化返回 404

有什么建议吗?

谢谢

【问题讨论】:

    标签: url-rewriting nginx


    【解决方案1】:

    这个正则表达式是完全错误的: ^/fixed-word/([^\?]+)$/([^\?]+)$

    如果你只需要创建一个 301 重定向,那么你应该使用这个:

    location /fixed-word/ {
        rewrite ^/fixed-word/(?:[^/]+)/(?:\d+)-(.+)$ /another-fixed-word/$1 permanent;
    }
    

    【讨论】:

      猜你喜欢
      • 2012-06-20
      • 1970-01-01
      • 2010-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-14
      • 1970-01-01
      相关资源
      最近更新 更多