让我说清楚:
选项 1)
您要输入以下 URL:
yoursite/wholesale/并且能够看到与您在: yoursite/products-page/wholesale/
完全相同的内容
实现这一点的最简单方法是添加一个“批发”页面并创建一个带有修改循环的自定义模板页面。
http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates
http://codex.wordpress.org/Function_Reference/query_posts
或者
选项2)
您要输入:
yoursite/wholesale/a-product/
并且能够看到相当于:
yoursite/products-page/wholesale/a-product/
如果这是您想要实现的目标,您应该专注于添加/修改 WordPress 自己的 RewriteRules,您应该避免使用 .htaccess,因为您可以指示 WP 了解任何给定的永久链接结构。
作为介绍,我建议您查看http://www.hongkiat.com/blog/wordpress-url-rewrite/
不要忘记:每次更改永久链接结构时,请转到Settings -> Permalinks
并单击保存更改,否则更改可能在您这样做之前不会应用。
我不确定这是否可以使用 .htaccess,但 WordPress 中的规则看起来像RewriteRule
以下示例的第一个所示:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^wholesale/(.+)/?$ /index.php?category_name=wholesale&name=$1 [NC] # (.+) represents the title of a post with the "wholesale" category
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
当你使用时add_rewrite_rule
应该看起来有点像:
add_rewrite_rule('^wholesale/([^/]*)/?','index.php?category_name=wholesale&name=matches[1]','top');
上面的示例仅在(.+)
/([^/]*)
表示帖子时才有效,如果它是自定义帖子类型,它将不起作用,因为您必须添加表示此类自定义帖子类型的变量。