V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
GASALA
V2EX  ›  问与答

在线求助,关于wordpress自定义文章类型在Nginx环境下的固定链接规则

  •  
  •   GASALA · 2013-04-22 00:54:48 +08:00 · 2688 次点击
    这是一个创建于 4038 天前的主题,其中的信息可能已经有所发展或是发生改变。
    好像Nginx下常用的那个固定链接规则不适用于自定义文章类型?应该怎么写呢?一直404
    6 条回复    1970-01-01 08:00:00 +08:00
    qq286735628
        1
    qq286735628  
       2013-04-22 01:57:37 +08:00
    location / {
    index index.html index.php;
    if (-f $request_filename/index.html){
    rewrite (.*) $1/index.html break;
    }
    if (-f $request_filename/index.php){
    rewrite (.*) $1/index.php;
    }
    if (!-f $request_filename){
    rewrite (.*) /index.php;
    }
    }

    参考:http://codex.wordpress.org/Nginx
    soli
        2
    soli  
       2013-04-22 10:06:29 +08:00
    if (!-d $request_filename){
    set $fd nd;
    }
    if (!-f $request_filename){
    set $fd nf$fd;
    }
    if ($fd = "nfnd"){
    rewrite (.*) /index.php last;
    }
    GASALA
        3
    GASALA  
    OP
       2013-04-24 16:05:48 +08:00
    @soli
    @qq286735628

    亲,感谢^_^这两个规则适合wordpress的自定义文章类型吗?我原有的文章发布后固定链接是正确的哦。不过新增加的自定义类型的文章,固定链接一直404。在本地的XAMPP环境下是没问题的。我新建的文章类型是“topic”,我在functions.php中使用了以下规则:

    //自定义文章类型静态规则
    add_filter('post_type_link','topic_post_type_link',1,3);
    function topic_post_type_link($link,$post=0){
    if($post->post_type == 'topic'){
    return home_url('topic/' . $post->ID . '/');
    }else{
    return $link;
    }
    }
    add_action('init','topic_rewrites_init');
    function topic_rewrites_init(){
    add_rewrite_rule('topic/([0-9]+)?$','index.php?post_type=topic&p=$matches[1]','top');

    在本地XAMPP环境下链接没有任何问题。但是到服务器上调试就出现404了,服务器是LNMP环境。
    GASALA
        4
    GASALA  
    OP
       2013-05-08 19:52:00 +08:00
    这个问题有人能帮助一下吗?具体描述在三楼,实在搞不定。

    谢谢。
    yxling
        5
    yxling  
       2013-05-08 20:03:38 +08:00
    我也不是很懂 你的问题 我也不太清楚
    这是我的配置文件
    server
    {
    listen 80;
    server_name www.yxl.me yxl.me;
    index index.html index.htm index.php default.html default.htm default.php;
    root /home/wwwroot/yxl.me;

    include wordpress.conf;
    location ~ .*\.(php|php5)?$
    {
    try_files $uri =404;
    fastcgi_pass unix:/tmp/php-cgi.sock;
    fastcgi_index index.php;
    include fcgi.conf;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
    expires 30d;
    }

    location ~ .*\.(js|css)?$
    {
    expires 12h;
    }

    access_log off;
    }



    ==============================================================
    还有就是不知道你能不能把你设置的链接 给个效果我看看 或许我能找到人帮你解决
    yxling
        6
    yxling  
       2013-05-08 20:29:57 +08:00
    if (-f $request_filename/index.html){
    rewrite (.*) $1/index.html break;
    }
    if (-f $request_filename/index.php){
    rewrite (.*) $1/index.php;
    }
    if (!-f $request_filename){
    rewrite (.*) /index.php;
    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1213 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:25 · PVG 02:25 · LAX 11:25 · JFK 14:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.