【发布时间】:2012-08-19 19:56:34
【问题描述】:
我正在尝试将我的网站从默认的 /year/month/day/post_title 永久链接更改为简单的 /post_title/ 链接,但是,在更改它时,我所有的旧链接都已损坏。我已经阅读了一个关于如何使用 .htaccess 在 Apache 上执行此操作的站点,但需要一些帮助来弄清楚如何使其与 nginx 的位置而不是 mod_rewrite 一起工作。
这是详细介绍如何在 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;
}
}
有人知道怎么解决吗?谢谢。
【问题讨论】:
-
我也试过添加重写^/[0-9]{4}/[0-9]{2}/[0-9]{2}/([a-z0- 9\-/]+) website.com/$1 永久;但是在位置 / {} 中不起作用。
标签: regex wordpress mod-rewrite nginx