WordPress 3.1.2 固定链接已损坏
我全新安装了 WordPress 3.1.2(未升级,但全新安装),不包含任何插件。
我在谷歌搜索中遇到了一个相当常见的问题,但我找不到适合我的解决方案。
我正在运行自定义分类法和自定义帖子类型,来自我的functions.php的代码:
register_post_type( 'product', array(
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product'),
'add_new_item' => __( 'Add New Product'),
'add_new' => __( 'Add a Product'),
'edit_item' => __( 'Edit Product'),
'new_item' => __( 'New Product'),
'view_item' => __( 'View Product'),
'search_items' => __( 'Search products' ),
'not_found' => __( 'No products found' ),
'not_found_in_trash' => __( 'No products found in Trash' )
),
'public' => true,
'supports' => array(
'title',
'editor'
),
'has_archive' => true,
'can_export' => true
));
register_taxonomy( 'product_category', 'product', array(
'hierarchical' => true,
'labels' => array(
'name' => 'Product Categories',
'singular_name' => 'Product Category',
'search_items' => __( 'Search Product Categories' ),
'all_items' => __( 'All Product Categories' ),
'parent_item' => __( 'Parent Product Category' ),
'parent_item_colon' => __( 'Parent Product Category:' ),
'edit_item' => __( 'Edit Product Category' ),
'update_item' => __( 'Update Product Category' ),
'add_new_item' => __( 'Add New Product Category' ),
'new_item_name' => __( 'New Product Category Name' ),
'menu_name' => __( 'Product Categories' ),
),
'public' => true,
'rewrite' => array(
'hierarchical' => true
)
));
问题是当我转到product_category
存档页面时,例如http://example.com/dairy-industry,我得到了 404。我已经尝试了无数的修复,包括
- 每种组合
rewrite
register_taxonomy
代码上的参数 - 重新保存永久链接
- 关闭永久链接,保存,然后再次打开它们,
- ,但首先从服务器中删除 .htaccess 文件
- 如上所述 wp_options 表中删除 rewrite_rules 选项
- ,但首先从具有类别基础和标签基础选项设置(和空白)的
,我也没有 $wp_rewrite->flush_rules() 中的任何地方我的主题。
最令人沮丧的是,在我的修复过程中的不同时间,由于我无法识别模式,自定义分类存档页面将再次开始工作,但常规页面将开始给我 404。它们永远不会同时工作,而且我无法弄清楚哪些步骤可以重复地使其中一个或另一个工作。这似乎完全是随机的。
更有趣的是,当自定义分类存档页面无法工作时,其中一个(乳制品行业
)会重定向到名称相似但不同的 slug (2011/04/dairy-industry-products
) 在给我 404 之前发布。
我很乐意分享任何可能有帮助的代码,只需询问即可。
有人能帮我解决这个令人困惑的难题吗?
I have a fresh install of WordPress 3.1.2 (not upgraded but installed fresh), containing no plugins whatsoever.
I'm having what seems to be from my googling a fairly common problem, but none of the solutions I can find work for me.
I have a custom taxonomy and a custom post type running, the code from my functions.php:
register_post_type( 'product', array(
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product'),
'add_new_item' => __( 'Add New Product'),
'add_new' => __( 'Add a Product'),
'edit_item' => __( 'Edit Product'),
'new_item' => __( 'New Product'),
'view_item' => __( 'View Product'),
'search_items' => __( 'Search products' ),
'not_found' => __( 'No products found' ),
'not_found_in_trash' => __( 'No products found in Trash' )
),
'public' => true,
'supports' => array(
'title',
'editor'
),
'has_archive' => true,
'can_export' => true
));
register_taxonomy( 'product_category', 'product', array(
'hierarchical' => true,
'labels' => array(
'name' => 'Product Categories',
'singular_name' => 'Product Category',
'search_items' => __( 'Search Product Categories' ),
'all_items' => __( 'All Product Categories' ),
'parent_item' => __( 'Parent Product Category' ),
'parent_item_colon' => __( 'Parent Product Category:' ),
'edit_item' => __( 'Edit Product Category' ),
'update_item' => __( 'Update Product Category' ),
'add_new_item' => __( 'Add New Product Category' ),
'new_item_name' => __( 'New Product Category Name' ),
'menu_name' => __( 'Product Categories' ),
),
'public' => true,
'rewrite' => array(
'hierarchical' => true
)
));
The problem is that when I go to a product_category
archive page, for example http://example.com/dairy-industry, I get a 404. I have tried about a gajillion fixes, including
- every combination of
rewrite
arguments on theregister_taxonomy
code - re-saving permalinks
- turning permalinks off, saving, then turning them on again
- the above, but first deleting the .htaccess file from the server
- the above, but first deleting the rewrite_rules option from the wp_options table
- having the category base and tag base option set (and blank)
I also do not have $wp_rewrite->flush_rules() anywhere in my theme.
The most frustrating thing is that at various times throughout my fixes, and with no pattern I can identify, the custom taxonomy archive pages will start working again, but the regular pages will start giving me 404s instead. They never work at the same time, and I can't figure out which steps will reproducibly make one or the other work. It seems to be totally random.
For a further bit of interestingness, when the custom taxonomy archive pages are not working, one of them (dairy-industry
) redirects to the slug of a similarly-named but different (2011/04/dairy-industry-products
) post before giving me a 404.
I'm happy to share any code that may be helpful, just ask.
Can anyone help me figure out this perplexing conundrum?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对我来说帮助了这个答案: word-press-permalinks-broken-fro-category-and-tags-404-error-page-not-found
只需检查您的插件以及是否有“简单标签” ” 或“Multipage Toolkit“ 编辑插件,并将: 替换
为:
之后,转到您的永久链接页面并更新它们...两次。起到了魅力的作用。
For me helped this answer: word-press-permalinks-broken-fro-category-and-tags-404-error-page-not-found
Simply Check your plugins and if you have “Simple Tags” or “Multipage Toolkit“ edit plugins, and replace:
with:
After, go to your permlinks page and update them... twice. Worked as a charm.
我之前遇到过一些问题。我发现,如果您有一个自定义帖子类型与其中一个页面同名,它可能会导致巨大的问题!这可能是您需要考虑的事情。
我现在使用插件来创建自定义帖子类型,因为它内置了 url 结构字段。该插件名为 CMS Press。
I've had some issues with this before. I found that if you have a custom post type with the same name as one of your page slugs, it can cause huge issues! This may be something you need to consider.
I now use a plugin to create my custom post types, as it has built in fields for the url structure. This plugin is called CMS Press.
我一直遇到这个问题,只有在从 3.1 升级到 3.1.2 后才出现(我们跳过了 3.1.1)。对于自定义帖子类型以及应用了自定义重写规则的任何地方(例如自定义提要链接),我都会收到 404 响应。
我设法让它与这个插件配合得很好:
http://wordpress。 org/extend/plugins/wcs-custom-permalinks-hotfix/
但是,我仍然时不时地收到这些页面的 404 错误 - 我怀疑何时添加了新帖子。当发生这种情况时,我可以通过转到永久链接设置页面并简单地点击“保存”来让它们再次工作。
请务必检查您的 htaccess 规则 - 该插件的网站有大量信息以及针对单站点和多站点设置的推荐 htaccess 规则:
http://wpcodesnippets.info/blog/wcs-custom-permalinks-hotfix.html
I have been experiencing this problem which only appeared after upgrading to 3.1.2 from 3.1 (we skipped 3.1.1). I get 404 response for custom post types and anywhere that a custom rewrite rule has been applied (e.g. custom feed links).
I managed to get it working reasonably well with this plugin:
http://wordpress.org/extend/plugins/wcs-custom-permalinks-hotfix/
However I still get these pages 404'ing every now and then - I suspect when a new post is added. When that happens I can get them working again by going to the permalink settings page and simply hitting save.
Be sure to check your htaccess rules - the website for the plugin has a lot of information and recommended htaccess rules for single and multisite setups:
http://wpcodesnippets.info/blog/wcs-custom-permalinks-hotfix.html
当我第一次遇到永久链接的 404 问题时,我很抓狂。它影响了我自己的所有网站以及我管理的几个网站。数百人使用了我编写的修补程序功能...然后响应用户的各种特殊情况...我们将其完善为您提到的插件。
文章原文在这里:
http://wpcodesnippets.info /blog/how-to-fix-the-wp-3-1-custom-permalinks-bug.html
我估计这个错误已经影响了数千个 WP 网站。但是,官方开发人员拒绝在后续更新中解决这个问题。幸运的是,该插件应该永久有效。
关于您偶尔出现的新帖子 404,我特别好奇您是否能找到罪魁祸首。这里有一个值得尝试的事情。一旦新帖子发生这种情况,请在您通常不使用的浏览器中打开您的网站......并查看是否可以从那里单击指向新帖子的链接。
当然,修改或访问永久链接结构的旧插件将需要较小的修改,直到 WP 决定解决该问题。
不管怎样,我很高兴这个插件能帮上忙。
When i first encountered this 404 issue with permalinks, I was frantic. It impacted all of my own sites and several that I manage. Hundreds of folks used a hotfix function that I'd coded ... and then responding to various special cases from users ... we perfected it to the plugin that you mention.
The original article is here:
http://wpcodesnippets.info/blog/how-to-fix-the-wp-3-1-custom-permalinks-bug.html
It is my estimation that this bug has impacted thousands of WP sites. But, the official developers have declined to address it in any subsequent updates. Fortunately, the plugin should work in perpetuity.
Regarding your occasional 404's for new posts, I'm particularly curious if you discover the culprit. Here's one thing to try. As soon as this happens with a new post, pull your site up in a browser that you don't normally use ... and see if you can click a link to the new post from there.
Certainly, older plugins that modify or access the permalink structure will need minor mods until WP decides to address the issue.
Anyway, I'm glad the plugin has helped.