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

2013-04-22 00:54:48 +08:00
 GASALA
好像Nginx下常用的那个固定链接规则不适用于自定义文章类型?应该怎么写呢?一直404
2702 次点击
所在节点    问与答
6 条回复
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
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
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
2013-05-08 19:52:00 +08:00
这个问题有人能帮助一下吗?具体描述在三楼,实在搞不定。

谢谢。
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
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;
}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/66552

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX