0

ウェブサイトをデフォルトの /year/month/day/post_title パーマリンクから単純な /post_title/ リンクに変更しようとしていますが、変更すると古いリンクがすべて壊れてしまいます。.htaccess を使用して Apache でそれを行う方法に関するサイトを読みましたが、mod_rewrite の代わりに nginx の場所で機能させる方法を理解するのに助けが必要です。
これは、Apache http://www.rickbeckman.org/how-to-update-your-wordpress-permalinks-without-causing-link-rot/
でそれを行う方法を詳しく説明しているサイトです。 そして、この htaccess を nginx に使用してみましたコンバータhttp://winginx.com/htaccessただし、正規表現が問題を引き起こしている可能性があり、nginx の起動時にこのエラーが発生します

    [emerg]: unknown directive "4}/[0-9]" in /usr/local/nginx/sites-enabled/website.com:19

そして、これは私の構成ファイルです

    server {
        listen   80;
        server_name  website.com;
        rewrite ^/(.*) http://www.website.com/$1 permanent;
   }

    server {
        listen   80;
        server_name www.website.com;
        error_log /home/user/public_html/website.com/log/error.log;
        client_max_body_size 10M;
        client_body_buffer_size 128k;

        location /  {
                    root   /home/user/public_html/website.com/public/;
                    index  index.php index.html;
                    try_files $uri $uri/ /index.php;
                    }
        location ~ ^/[0-9]{4}/[0-9]{2}/[0-9]{2}/([a-z0-9\-/]+) {
                    rewrite ^(.*)$ http://website.com/$1 permanent;
                    }
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$
                            {
        fastcgi_read_timeout 120;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include /usr/local/nginx/conf/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /home/user/public_html/website.com/public/$fastcgi_script_name;
                            }
  }

誰でもそれを修正する方法を知っていますか?ありがとう。

4

2 に答える 2

0

修正は簡単です:

location ~ ^/[0-9]{4}/[0-9]{2}/[0-9]{2}/([a-z0-9\-/]+) {
  rewrite ^(.*)$ http://website.com/$1 permanent;
}

上記の問題は、リライトによって後方参照がリセットされるため、$ 1は、ロケーションの一致からの$ 1ではなく、リライトの一致からのURL全体と一致するようになることです。以下が機能するはずです。

location ~ ^/[0-9]{4}/[0-9]{2}/[0-9]{2}/([a-z0-9\-/]+) {
  set $post_title $1;
  rewrite ^(.*)$ http://website.com/$post_title permanent;
}

(または、書き換えルールの正規表現を再度一致させます)

于 2012-08-19T20:48:22.920 に答える
0

正規表現を引用符で囲んで修正しました。

    rewrite "^/[0-9]{4}/[0-9]{2}/[0-9]{2}/([a-z0-9\-/]+)" http://www.website.com/$1;
于 2012-08-20T05:17:12.510 に答える