WordPress 和 ReWriteRule

发布于 2024-09-11 15:56:11 字数 418 浏览 0 评论 0原文

我的主题中有一个产品详细信息模板,可根据 URL 处理不同产品的显示。

默认情况下,WordPress 将允许通过附加到 URL 来将数字传递到模板页面:product-details/3/

但是,我想使用 slug 使其更加 SEO 友好: 产品/凉鞋。然而,当我这样做时,WordPress 默认不再找到该页面。

我尝试了以下 ReWriteRule 但没有成功。

RewriteRule ^product/([\w\-]+)/?$ product-details/?slug=$1 [L]

我怎样才能把这个自定义的slug发送到模板。我更愿意将所有内容保留在 WordPress 中,但我愿意添加 ReWriteRule

I have a product-details template in my theme that handles display for different products based on the URL.

By default, WordPress will allow a number to be passed to the template page by appending to the URL: product-details/3/

However, I want to make this to be more SEO Friendly using a slug: product/sandals. Yet, when I do so, WordPress no longer finds the page by default.

I tried the following ReWriteRule with no luck.

RewriteRule ^product/([\w\-]+)/?$ product-details/?slug=$1 [L]

How can I have this custom slug sent to the template. I would prefer to keep everything in WordPress, but am willing to add the ReWriteRule.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

电影里的梦 2024-09-18 15:56:11

感谢 Richard 在 OP 评论中回答了这个问题。为了完整起见,我突出显示了该资源,并将该问题标记为已回答。

http://codex.wordpress.org/Function_Reference/WP_Rewrite

Credit to Richard for answering this in the OP comments. I've highlighted the resource for completeness and to mark this question answered.

http://codex.wordpress.org/Function_Reference/WP_Rewrite

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文