Function Reference/WP Rewrite:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
无编辑摘要
无编辑摘要
 
第1行: 第1行:
This document assumes familiarity with [http://httpd.apache.org Apache]'s [http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html mod_rewrite]. If you've never heard of this before, try reading Sitepoint's [http://www.sitepoint.com/article/guide-url-rewriting Beginner's Guide to URL Rewriting].
阅读这个文件的前提是,你熟悉[http://httpd.apache.org Apache]的[http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html mod_rewrite]。如果你从没有听说过这个,试着阅读[http://www.sitepoint.com/article/guide-url-rewriting Beginner's Guide to URL Rewriting]。
阅读这个文件的前提是,你熟悉[http://httpd.apache.org Apache]的[http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html mod_rewrite]。如果你从没有听说过这个,试着阅读[http://www.sitepoint.com/article/guide-url-rewriting Beginner's Guide to URL Rewriting]。
==Role of WP_Rewrite==


== WP_Rewrite角色==
== WP_Rewrite角色==
<tt>WP_Rewrite</tt> is WordPress' class for managing the rewrite rules that allow you to use [[WordPress:Introduction_to_Blogging#Pretty_Permalinks|Pretty Permalinks]] feature. It has several methods that generate the rewrite rules from values in the database. It is used internally when updating the rewrite rules, and also to find the URL of a specific post, Page, category archive, etc.. It's defined in <tt>wp-includes/rewrite.php</tt> and a global [[WordPress:Glossary#Singleton|singleton]], <tt>$wp_rewrite</tt>, is initialised in <tt>wp-settings.php</tt>.
<tt>WP_Rewrite</tt>是WordPress的class,用来管理rewrite 规则,使你能够使用[[WordPress:Introduction_to_Blogging#Pretty_Permalinks|Pretty Permalinks]]功能。从数据库中的参数值中产生rewrite 规则,有几种方法,当上传rewrite 规则的时候,是在内部使用的,同时查找某篇文章,某个网页,类别归档,等等的URL。定义在<tt>wp-includes/rewrite.php</tt>中而且一个全局[[WordPress:Glossary#Singleton|singleton]], <tt>$wp_rewrite</tt>,在<tt>wp-settings.php</tt>中初始化。
<tt>WP_Rewrite</tt>是WordPress的class,用来管理rewrite 规则,使你能够使用[[WordPress:Introduction_to_Blogging#Pretty_Permalinks|Pretty Permalinks]]功能。从数据库中的参数值中产生rewrite 规则,有几种方法,当上传rewrite 规则的时候,是在内部使用的,同时查找某篇文章,某个网页,类别归档,等等的URL。定义在<tt>wp-includes/rewrite.php</tt>中而且一个全局[[WordPress:Glossary#Singleton|singleton]], <tt>$wp_rewrite</tt>,在<tt>wp-settings.php</tt>中初始化。


==Methods and Properties==
==方法和属性==
==方法和属性==
This is the formal documentation of <tt>WP_Rewrite</tt>. Try not to access or set the properties directly, instead use the methods to interact with the <tt>$wp_rewrite</tt> object.
这是<tt>WP_Rewrite</tt>一个正式的文档。试着不要直接地访问或者设置属性,而是使用方法与<tt>$wp_rewrite</tt> object互动。
这是<tt>WP_Rewrite</tt>一个正式的文档。试着不要直接地访问或者设置属性,而是使用方法与<tt>$wp_rewrite</tt> object互动。


===Properties===
===属性===
===属性===
; <tt>$permalink_structure</tt> : The permalink structure as in the database. This is what you set on the Permalink Options page, and includes 'tags' like %year%, %month% and %post_id%.


; <tt>$permalink_structure</tt> :数据库中的permalnk结构。这是你在Permalink选项网页上设置的内容,而且包含'标签' 像 %year%, %month% 和 %post_id%。
; <tt>$permalink_structure</tt> :数据库中的permalnk结构。这是你在Permalink选项网页上设置的内容,而且包含'标签' 像 %year%, %month% 和 %post_id%。
; <tt>$category_base</tt> : Anything to be inserted before category archive URLs. Defaults to 'category/'.


; <tt>$category_base</tt> :在类别归档URLs之前插入的任何内容。默认为'类别/'。
; <tt>$category_base</tt> :在类别归档URLs之前插入的任何内容。默认为'类别/'。
; <tt>$category_structure</tt> : Structure for category archive URLs. This is just the <tt>$category_base</tt> plus '%category%'.


; <tt>$category_structure</tt> :类别归档URLs的结构。这只是<tt>$category_base</tt>和'%category%'。
; <tt>$category_structure</tt> :类别归档URLs的结构。这只是<tt>$category_base</tt>和'%category%'。
; <tt>$author_base</tt> : Anything to be inserted before author archive URLs. Defaults to 'author/'.


; <tt>$author_base</tt> :作者归档URLs之前插入的任何内容。默认为'作者/'。
; <tt>$author_base</tt> :作者归档URLs之前插入的任何内容。默认为'作者/'。
; <tt>$author_structure</tt> : Structure for author archive URLs. This is just the <tt>$author_base</tt> plus '%author%'.


; <tt>$author_structure</tt> :作者归档URLs的结构。这只是<tt>$author_base</tt>和 '%author%'。
; <tt>$author_structure</tt> :作者归档URLs的结构。这只是<tt>$author_base</tt>和 '%author%'。
; <tt>$feed_base</tt> : Anything to be inserted before feed URLs. Defaults to 'feed/'.


; <tt>$feed_base</tt> : feed URLs之前插入的任何内容。默认为'feed/'。
; <tt>$feed_base</tt> : feed URLs之前插入的任何内容。默认为'feed/'。
; <tt>$feed_structure</tt> : Structure for feed URLs. This is just the <tt>$feed_base</tt> plus '%feed%'.


; <tt>$feed_structure</tt> : feed URLs的结构。这只是<tt>$feed_base</tt> 和 '%feed%'。
; <tt>$feed_structure</tt> : feed URLs的结构。这只是<tt>$feed_base</tt> 和 '%feed%'。
; <tt>$search_base</tt> : Anything to be inserted before searchs. Defaults to 'search/'.


; <tt>$search_base</tt> : searchs之前插入的任何内容。默认为'搜索/'。
; <tt>$search_base</tt> : searchs之前插入的任何内容。默认为'搜索/'。
; <tt>$search_structure</tt> : Structure for search URLs. This is just the <tt>$search_base</tt> plus '%search%'.


; <tt>$search_structure</tt> :搜索URLs的结构。这只是<tt>$search_base</tt> 和 '%search%'。
; <tt>$search_structure</tt> :搜索URLs的结构。这只是<tt>$search_base</tt> 和 '%search%'。
; <tt>$comments_base</tt> : Anything to be inserted just before the <tt>$feed_structure</tt> to get the latest comments feed. Defaults to 'comments'.


; <tt>$comments_base</tt> : <tt>$feed_structure</tt>之前插入的任何内容,以得到最新的评论feed。默认为'评论'。
; <tt>$comments_base</tt> : <tt>$feed_structure</tt>之前插入的任何内容,以得到最新的评论feed。默认为'评论'。
; <tt>$comments_feed_structure</tt> : The structure for the latest comments feed. This is just <tt>$comments_base</tt> plus <tt>$feed_base</tt> plus '%feed%'.


; <tt>$comments_feed_structure</tt> :最新的评论feed的结构。这只是<tt>$comments_base</tt> 和 <tt>$feed_base</tt> 和'%feed%'。
; <tt>$comments_feed_structure</tt> :最新的评论feed的结构。这只是<tt>$comments_base</tt> 和 <tt>$feed_base</tt> 和'%feed%'。
; <tt>$date_structure</tt> : Structure for dated archive URLs. Tries to be '%year%/%monthnum%/%day%', '%day%/%monthnum%/%year%' or '%monthnum%/%day%/%year%', but if none of these are detected in your <tt>$permalink_structure</tt>, defaults to '%year%/%monthnum%/%day%'. Various functions use this structure to obtain less specific structures: for example, <tt>get_year_permastruct()</tt> simply removes the '%monthnum%' and '%day%' tags from <tt>$date_structure</tt>.


; <tt>$date_structure</tt> :有日期的归档URLs的结构。试着为'%year%/%monthnum%/%day%', '%day%/%monthnum%/%year%' 或者 '%monthnum%/%day%/%year%',但是如果在你的<tt>$permalink_structure</tt>中没有发现这些,默认为'%year%/%monthnum%/%day%'。不同的函数使用这个结构得到更普通的结构:例如<tt>get_year_permastruct()</tt>这是从<tt>$date_structure</tt>中移除了'%monthnum%' 和 '%day%'标签。
; <tt>$date_structure</tt> :有日期的归档URLs的结构。试着为'%year%/%monthnum%/%day%', '%day%/%monthnum%/%year%' 或者 '%monthnum%/%day%/%year%',但是如果在你的<tt>$permalink_structure</tt>中没有发现这些,默认为'%year%/%monthnum%/%day%'。不同的函数使用这个结构得到更普通的结构:例如<tt>get_year_permastruct()</tt>这是从<tt>$date_structure</tt>中移除了'%monthnum%' 和 '%day%'标签。
; <tt>$page_structure</tt> : Structure for Pages. Just '%pagename%'.


; <tt>$page_structure</tt> :网页结构。只是'%pagename%'。
; <tt>$page_structure</tt> :网页结构。只是'%pagename%'。
; <tt>$front</tt> : Anything up to the start of the first tag in your <tt>$permalink_structure</tt>.


; <tt>$front</tt> :任何关于你的<tt>$permalink_structure</tt>第一个标签启动的内容。
; <tt>$front</tt> :任何关于你的<tt>$permalink_structure</tt>第一个标签启动的内容。
; <tt>$root</tt> : The root of your WordPress install. Prepended to all structures.


; <tt>$root</tt> :你的WordPress安装的根,是所有结构开始的地方。
; <tt>$root</tt> :你的WordPress安装的根,是所有结构开始的地方。
; <tt>$matches</tt> : Used internally when calculating back references for the redirect part of the rewrite rules.


; <tt>$matches</tt> :当计算rewrite 规则的references的时候,在内部使用这个。
; <tt>$matches</tt> :当计算rewrite 规则的references的时候,在内部使用这个。
第94行: 第52行:


; <tt>$rewritecode</tt> :permalink结构可以使用的所有标签的数组。请看看[[WordPress:Using_Permalinks#Structure_Tags|Using Permalinks]]的列表。
; <tt>$rewritecode</tt> :permalink结构可以使用的所有标签的数组。请看看[[WordPress:Using_Permalinks#Structure_Tags|Using Permalinks]]的列表。
; <tt>$rewritereplace</tt> : What each tag will be replaced with for the regex part of the rewrite rule. The first element in <tt>$rewritereplace</tt> is the regex for the first element in <tt>$rewritecode</tt>, the second corresponds to the second, and so on.


; <tt>$rewritereplace</tt> :对于rewrite 规则的regex部分,每个标签会由什么取代。<tt>$rewritereplace</tt>中的第一个元素是<tt>$rewritecode</tt>中第一个元素的regex,第二个元素对应着第二个,等等。
; <tt>$rewritereplace</tt> :对于rewrite 规则的regex部分,每个标签会由什么取代。<tt>$rewritereplace</tt>中的第一个元素是<tt>$rewritecode</tt>中第一个元素的regex,第二个元素对应着第二个,等等。
; <tt>$queryreplace</tt> : What each tag will be replaced with in the rewrite part of the rewrite rule. The same correspondance applies here as with <tt>$rewritereplace</tt>.


; <tt>$queryreplace</tt> :在rewrite规则的rewrite部分,每个标签会由什么来取代。在<tt>$rewritereplace</tt>中可以取代的部分,在这里也可以适用。
; <tt>$queryreplace</tt> :在rewrite规则的rewrite部分,每个标签会由什么来取代。在<tt>$rewritereplace</tt>中可以取代的部分,在这里也可以适用。
===Methods===


===方法===
===方法===
; <tt>add_rewrite_tag(<var>$tag</var>, <var>$pattern</var>, <var>$query</var>)</tt> : add an element to the <var>$rewritecode</var>, <var>$rewritereplace</var> and <var>$queryreplace</var> arrays using each parameter respectively. If <var>$tag</var> already exists in <var>$rewritecode</var>, the existing value will be overwritten.
; <tt>add_rewrite_tag(<var>$tag</var>, <var>$pattern</var>, <var>$query</var>)</tt> :给<var>$rewritecode</var>, <var>$rewritereplace</var>和<var>$queryreplace</var>添加一个元素,单独地使用每个参数。如果<var>$rewritecode</var>中已经存在<var>$tag</var>,当前的参数值就会被覆盖。
; <tt>add_rewrite_tag(<var>$tag</var>, <var>$pattern</var>, <var>$query</var>)</tt> :给<var>$rewritecode</var>, <var>$rewritereplace</var>和<var>$queryreplace</var>添加一个元素,单独地使用每个参数。如果<var>$rewritecode</var>中已经存在<var>$tag</var>,当前的参数值就会被覆盖。
; <tt>flush_rules()</tt> : Regenerate the rewrite rules and save them to the database


; <tt>flush_rules()</tt> :重新产生rewrite规则,并将这个规则保存到数据库中。
; <tt>flush_rules()</tt> :重新产生rewrite规则,并将这个规则保存到数据库中。
; <tt>generate_rewrite_rule(<var>$permalink_structure</var>, <var>$walk_dirs</var> = false)</tt> : Generates a no-frills rewrite rule from the permalink structure. No rules for extra pages or feeds will be created.


; <tt>generate_rewrite_rule(<var>$permalink_structure</var>, <var>$walk_dirs</var> = false)</tt> :从permalink结构中产生不提供必要服务的rewrite规则。没有将要创建的额外网页或者feeds的规则。
; <tt>generate_rewrite_rule(<var>$permalink_structure</var>, <var>$walk_dirs</var> = false)</tt> :从permalink结构中产生不提供必要服务的rewrite规则。没有将要创建的额外网页或者feeds的规则。


; <tt>generate_rewrite_rules(<var>$permalink_structure</var>, <var>$ep_mask = EP_NONE</var>, <var>$page</var> = true, <var>$feed</var> = true, <var>$forcomments</var> = false, <var>$walk_dirs</var> = true)</tt> : A large function that generates the rewrite rules for a given structure, <var>$permalink_structure</var>. If <var>$page</var> is true, an extra rewrite rule will be generated for accessing different pages (e.g. /category/tech/page/2 points to the second page of the 'tech' category archive). If <var>$feed</var> is true, extra rewrite rules will be generated for obtaining a feed of the current page, and if <var>$forcomments</var> is true, this will be a comment feed. If <var>$walk_dirs</var> is true, then a rewrite rule will be generated for each directory of the structure provided, e.g. if you provide it with '/%year%/%month%/%day/', rewrite rules will be generated for '/%year%/', /%year%/%month%/' and '/%year%/%month%/%day%/'. This returns an associative array using the regex part of the rewrite rule as the keys and redirect part of the rewrite rule as the value.
; <tt>generate_rewrite_rules(<var>$permalink_structure</var>, <var>$ep_mask = EP_NONE</var>, <var>$page</var> =true, <var>$feed</var> = true, <var>$forcomments</var> = false, <var>$walk_dirs</var> =true)</tt> : 一个很大的函数,为一个给定的结构<var>$permalink_structure</var>产生rewrite规则。如果<var>$page</var> 是true,会产生额外的rewrite 规则,来访问不同的网页(例如 /category/tech/page/2 指向'tech' 类别归档的第二个页面)。如果<var>$feed</var> 是true,会产生额外的rewrite规则,得到当前页面的feed,而且如果<var>$walk_dirs</var> 是true,那么会产生当前结构的每个目录的rewrite规则,例如,如果你提供 '/%year%/%month%/%day/', rewrite 规则会产生 '/%year%/', /%year%/%month%/' 和'/%year%/%month%/%day%/'。这返回了结合数组,使用rewrite 规则的regex部分作为keys,使用 redirect part of the rewrite 规则的redirect部分作为参数值。
 
; <tt>generate_rewrite_rules(<var>$permalink_structure</var>, <var>$ep_mask = EP_NONE</var>, <var>$page</var> =正确的, <var>$feed</var> = 正确的, <var>$forcomments</var> = 错误的, <var>$walk_dirs</var> =正确的)</tt> : 一个很大的函数,为一个给定的结构<var>$permalink_structure</var>产生rewrite规则。如果<var>$page</var> 是正确的,会产生额外的rewrite 规则,来访问不同的网页(例如 /category/tech/page/2 指向'tech' 类别归档的第二个页面)。如果<var>$feed</var> 是正确的,会产生额外的rewrite规则,得到当前页面的feed,而且如果<var>$walk_dirs</var> 是正确的,那么会产生当前结构的每个目录的rewrite规则,例如,如果你提供 '/%year%/%month%/%day/', rewrite 规则会产生 '/%year%/', /%year%/%month%/' 和'/%year%/%month%/%day%/'。这返回了结合数组,使用rewrite 规则的regex部分作为keys,使用 redirect part of the rewrite 规则的redirect部分作为参数值。
 
; <tt>get_date_permastruct()</tt>, <tt>get_category_permastruct()</tt>, <tt>get_date_permastruct()</tt> etc. : Populates the corresponding property (e.g., <var>$date_structure</var> for <tt>get_date_permastruct()</tt>) if it's not already set and returns it. The functions <tt>get_month_permastruct()</tt> and <tt>get_year_permastruct()</tt> don't have a corresponding property: they work out the structure by taking the <var>$date_structure</var> and removing tags that are more specific than they need (i.e., <tt>get_month_permastruct()</tt> removes the '%day%' tag, as it only needs to specify the year and month).


; <tt>get_date_permastruct()</tt>, <tt>get_category_permastruct()</tt>, <tt>get_date_permastruct()</tt>等等 :在相关的属性上加上内容(例如<var>$date_structure</var>关于<tt>get_date_permastruct()</tt>)。如果没有设置,将其返回。函数<tt>get_month_permastruct()</tt> 和<tt>get_year_permastruct()</tt>没有相关的属性:是通过获得<var>$date_structure</var>并且移除其不需要的标签(如<tt>get_month_permastruct()</tt> 移除了'%day%' 标签,因为其只要表明年份和月份)得到结构。
; <tt>get_date_permastruct()</tt>, <tt>get_category_permastruct()</tt>, <tt>get_date_permastruct()</tt>等等 :在相关的属性上加上内容(例如<var>$date_structure</var>关于<tt>get_date_permastruct()</tt>)。如果没有设置,将其返回。函数<tt>get_month_permastruct()</tt> 和<tt>get_year_permastruct()</tt>没有相关的属性:是通过获得<var>$date_structure</var>并且移除其不需要的标签(如<tt>get_month_permastruct()</tt> 移除了'%day%' 标签,因为其只要表明年份和月份)得到结构。
; <tt>init()</tt> : Set up the object, set <var>$permalink_structure</var> and <var>$category_base</var> from the database. Set <var>$root</var> to <var>$index</var> plus '/'. Set <var>$front</var> to everything up to the start of the first tag in the permalink structure. Unset all other properties.


; <tt>init()</tt> :设置object,从数据库中设置<var>$permalink_structure</var>和<var>$category_base</var>。将<var>$root</var>设置为<var>$index</var>加上'/'。将<var>$front</var>设置为permalink结构中第一个标签开始的任何内容。取消所有其它属性。
; <tt>init()</tt> :设置object,从数据库中设置<var>$permalink_structure</var>和<var>$category_base</var>。将<var>$root</var>设置为<var>$index</var>加上'/'。将<var>$front</var>设置为permalink结构中第一个标签开始的任何内容。取消所有其它属性。
; <tt>mod_rewrite_rules()</tt> : returns a string (not an array) of all the rules. They are wrapped in an Apache <tt>[http://httpd.apache.org/docs/2.0/mod/core.html#ifmodule &lt;IfModule&gt;]</tt> block, to ensure mod_rewrite is enabled.


; <tt>mod_rewrite_rules()</tt> :返回所有规则的字符串(不是数组)。包含在Apache <tt>[http://httpd.apache.org/docs/2.0/mod/core.html#ifmodule &lt;IfModule&gt;]</tt> block,确保激活了mod_rewrite。
; <tt>mod_rewrite_rules()</tt> :返回所有规则的字符串(不是数组)。包含在Apache <tt>[http://httpd.apache.org/docs/2.0/mod/core.html#ifmodule &lt;IfModule&gt;]</tt> block,确保激活了mod_rewrite。
; <tt>page_rewrite_rules()</tt> : Returns the set of rules for any Pages you have created.


; <tt>page_rewrite_rules()</tt> :返回你已经创建的任何网页的规则。
; <tt>page_rewrite_rules()</tt> :返回你已经创建的任何网页的规则。
; <tt>rewrite_rules()</tt> : populate and return the <var>$rules</var> variable with an associative array as in <tt>generate_rewrite_rules()</tt>. This is generated from the post, date, comment, search, category, authors and page structures.


; <tt>rewrite_rules()</tt> :如<tt>generate_rewrite_rules()</tt>中那样,使用结合的数组填充并且返回<var>$rules</var>变数。这是从文章,日期,评论,搜索,类别,作者和网页结构中返回的。
; <tt>rewrite_rules()</tt> :如<tt>generate_rewrite_rules()</tt>中那样,使用结合的数组填充并且返回<var>$rules</var>变数。这是从文章,日期,评论,搜索,类别,作者和网页结构中返回的。
; <tt>set_category_base(<var>$category_base</var>)</tt> : Change the category base.


; <tt>set_category_base(<var>$category_base</var>)</tt> :更改类别基础。
; <tt>set_category_base(<var>$category_base</var>)</tt> :更改类别基础。
; <tt>set_permalink_structure(<var>$permalink_structure</var>)</tt> : Change the permalink structure.


; <tt>set_permalink_structure(<var>$permalink_structure</var>)</tt> : 更改permalink 结构。
; <tt>set_permalink_structure(<var>$permalink_structure</var>)</tt> : 更改permalink 结构。


; <tt>using_index_permalinks()</tt> :如果你的博客使用PATHINFO permalinks,返回<tt>true</tt>。


; <tt>using_mod_rewrite_permalinks</tt> :如果你的博客通过mod_rewrite使用"pretty"permalinks,返回<tt>true</tt>。


; <tt>using_index_permalinks()</tt> : Returns <tt>true</tt> if your blog is using PATHINFO permalinks.
; <tt>using_permalinks()</tt> :如果你的博客正在使用任何permalink结构(例如,不是默认的查询URIs <tt>?p=n</tt>, <tt>?cat=n</tt>),返回<tt>true</tt>。
 
; <tt>using_index_permalinks()</tt> :如果你的博客使用PATHINFO permalinks,返回<tt>正确的</tt>。
 
; <tt>using_mod_rewrite_permalinks</tt> : Returns <tt>true</tt> your blog is using "pretty" permalinks via mod_rewrite.
 
; <tt>using_mod_rewrite_permalinks</tt> :如果你的博客通过mod_rewrite使用"pretty"permalinks,返回<tt>正确的</tt>。
 
; <tt>using_permalinks()</tt> : Returns <tt>true</tt> if your blog is using any permalink structure (i.e. not the default query URIs <tt>?p=n</tt>, <tt>?cat=n</tt>).
 
; <tt>using_permalinks()</tt> :如果你的博客正在使用任何permalink结构(例如,不是默认的查询URIs <tt>?p=n</tt>, <tt>?cat=n</tt>),返回<tt>正确的</tt>。
 
; <tt>WP_Rewrite</tt> (constructor) : Call <tt>init()</tt>.


; <tt>WP_Rewrite</tt> (构造器) : 调用 <tt>init()</tt>。
; <tt>WP_Rewrite</tt> (构造器) : 调用 <tt>init()</tt>。
; <tt>wp_rewrite_rules()</tt> : returns the array of rewrite rules as in <tt>rewrite_rules()</tt>, but using <tt><var>$matches</var>[xxx]</tt> in the (where xxx is a number) instead of the normal mod_rewrite backreferences, <var>$xxx</var> (where xxx is a number). This is useful when you're going to be using the rules inside PHP, rather than writing them out to a .htaccess file.


; <tt>wp_rewrite_rules()</tt> :如<tt>rewrite_rules()</tt>,返回rewrite规则的数组,但是使用<tt><var>$matches</var>[xxx]</tt>(xxx是个数字的位置),而不是普通的mod_rewrite backreferences,<var>$xxx</var>(xxx是个数字的位置)。当你准备在PHP内部使用规则的时候而不是在.htaccess文件中编写,这很有用。
; <tt>wp_rewrite_rules()</tt> :如<tt>rewrite_rules()</tt>,返回rewrite规则的数组,但是使用<tt><var>$matches</var>[xxx]</tt>(xxx是个数字的位置),而不是普通的mod_rewrite backreferences,<var>$xxx</var>(xxx是个数字的位置)。当你准备在PHP内部使用规则的时候而不是在.htaccess文件中编写,这很有用。


==Plugin Hooks==
==插件Hooks==
==插件Hooks==
As the rewrite rules are a crucial part of your weblog functionality, WordPress allows plugins to hook into the generation process at several points. <tt>rewrite_rules()</tt>, specifically, contains nine filters and one hook for really precise control over the rewrite rules process. Here's what you can filter in <tt>rewrite_rules()</tt>:


因为rewrite规则是你的网络博客泛函性的一个重要的方面,WordPress允许插件hook into几点的产生过程。<tt>rewrite_rules()</tt>包含有九个过滤器和一个hook来精确地控制rewrite规则的过程。下面是你可以在<tt>rewrite_rules()</tt>中过滤什么:
因为rewrite规则是你的网络博客泛函性的一个重要的方面,WordPress允许插件hook into几点的产生过程。<tt>rewrite_rules()</tt>包含有九个过滤器和一个hook来精确地控制rewrite规则的过程。下面是你可以在<tt>rewrite_rules()</tt>中过滤什么:
* To filter the rewrite rules generated for permalink URLs, use <tt>post_rewrite_rules</tt>.


*要过滤为permalinks URLs产生的重写规则,请使用<tt>post_rewrite_rules</tt>。
*要过滤为permalinks URLs产生的重写规则,请使用<tt>post_rewrite_rules</tt>。
* To filter the rewrite rules generated for dated archive URLs, use <tt>date_rewrite_rules</tt>.


*要过滤为日期归档 URLs产生的重写规则,请使用<tt>date_rewrite_rules</tt>。
*要过滤为日期归档 URLs产生的重写规则,请使用<tt>date_rewrite_rules</tt>。
* To filter the rewrite rules generated for category archive URLs, use <tt>category_rewrite_rules</tt>.


*要过滤为类别归档 URLs产生的重写规则,请使用<tt>category_rewrite_rules</tt>。
*要过滤为类别归档 URLs产生的重写规则,请使用<tt>category_rewrite_rules</tt>。
* To filter the rewrite rules generated for search URLs, use <tt>search_rewrite_rules</tt>.


*要过滤为搜索 URLs产生的重写规则,请使用<tt>search_rewrite_rules</tt>。
*要过滤为搜索 URLs产生的重写规则,请使用<tt>search_rewrite_rules</tt>。
* To filter the rewrite rules generated for the latest comment feed URLs, use <tt>comments_rewrite_rules</tt>.


*要过滤为最近评论feed URLs产生的重写规则,请使用<tt>comments_rewrite_rules</tt>。
*要过滤为最近评论feed URLs产生的重写规则,请使用<tt>comments_rewrite_rules</tt>。
* To filter the rewrite rules generated for author archive URLs, use <tt>author_rewrite_rules</tt>.


*要过滤为作者归档 URLs产生的重写规则,请使用<tt>author_rewrite_rules</tt>。
*要过滤为作者归档 URLs产生的重写规则,请使用<tt>author_rewrite_rules</tt>。
* To filter the rewrite rules generated for your Pages, use <tt>page_rewrite_rules</tt>.


*要过滤为你的网页产生的重写规则,请使用<tt>page_rewrite_rules</tt>。
*要过滤为你的网页产生的重写规则,请使用<tt>page_rewrite_rules</tt>。
* To filter the rewrite rules generated for the root of your weblog, use <tt>root_rewrite_rules</tt>.


*要过滤为你的网络日志根目录产生的重写规则,请使用<tt>root_rewrite_rules</tt>。
*要过滤为你的网络日志根目录产生的重写规则,请使用<tt>root_rewrite_rules</tt>。
* To filter the whole lot, use <tt>rewrite_rules_array</tt>.


*要过滤整个内容,请使用<tt>rewrite_rules_array</tt>。
*要过滤整个内容,请使用<tt>rewrite_rules_array</tt>。
* The action hook <tt>generate_rewrite_rules</tt> runs <strong>after</strong> all the rules have been created. If your function takes a  parameter, it will be passed a [http://www.php.net/manual/en/language.references.php reference] to the entire <tt>$wp_rewrite</tt> object.


* action hook <tt>generate_rewrite_rules</tt>在所有规则创建<strong>之后</strong>,才运行。如果你的函数获得一个参数,会得到[http://www.php.net/manual/en/language.references.php reference]传递到整个<tt>$wp_rewrite</tt> object。
* action hook <tt>generate_rewrite_rules</tt>在所有规则创建<strong>之后</strong>,才运行。如果你的函数获得一个参数,会得到[http://www.php.net/manual/en/language.references.php reference]传递到整个<tt>$wp_rewrite</tt> object。
<tt>mod_rewrite_rules()</tt> is the function that takes the array generated by <tt>rewrite_rules()</tt> and actually turns it into a set of rewrite rules for the .htaccess file. This function also has a filter, <tt>mod_rewrite_rules</tt>, which will pass functions the string of all the rules to be written out to .htaccess, including the <tt>&lt;IfModule&gt;</tt> surrounding section. (Note: you may also see plugins using the <tt>rewrite_rules</tt> hook, but this is [[WordPress:Glossary#Deprecated|deprecated]]).


<tt>mod_rewrite_rules()</tt>是个函数,获得<tt>rewrite_rules()</tt>产生的数组,而且将这个转变为.htaccess文件的rewrite规则。这个函数也有过滤器<tt>mod_rewrite_rules</tt>,会传递函数所有规则的字符串,为.htaccess编写,包含<tt>&lt;IfModule&gt;</tt>周围的部分。(注:你可能也会看到插件使用<tt>rewrite_rules</tt>hook,但是这个已经[[WordPress:Glossary#Deprecated|取消了]])。
<tt>mod_rewrite_rules()</tt>是个函数,获得<tt>rewrite_rules()</tt>产生的数组,而且将这个转变为.htaccess文件的rewrite规则。这个函数也有过滤器<tt>mod_rewrite_rules</tt>,会传递函数所有规则的字符串,为.htaccess编写,包含<tt>&lt;IfModule&gt;</tt>周围的部分。(注:你可能也会看到插件使用<tt>rewrite_rules</tt>hook,但是这个已经[[WordPress:Glossary#Deprecated|取消了]])。
===Examples===


===例子===
===例子===
(See also: [[WordPress:Custom_Queries#Permalinks_for_Custom_Archives|Permalinks for Custom Archives]])
(也看看:[[WordPress:Custom_Queries#Permalinks_for_Custom_Archives|自定义归档的Permalinks]])
(也看看:[[WordPress:Custom_Queries#Permalinks_for_Custom_Archives|自定义归档的Permalinks]])


The most obvious thing a plugin would do with the <tt>$wp_rewrite</tt> object is add its own rewrite rules. This is remarkably simple. Filter the generic <tt>rewrite_rules_array</tt>. The [http://vapourtrails.ca/wp-keywords Jerome's Keywords] plugin does this to enable URLs like <tt><nowiki>http://example.com/tag/sausages</nowiki></tt>.
插件处理<tt>$wp_rewrite</tt> 对象,典型的就是添加插件自身的rewrite 规则。这非常简单。过滤一般的<tt>rewrite_rules_array</tt>。[http://vapourtrails.ca/wp-keywords Jerome's Keywords]插件执行这个操作,激活URLs,如<tt><nowiki>http://example.com/tag/sausages</nowiki></tt>。
 
插件处理<tt>$wp_rewrite</tt> object,典型的就是添加插件自身的rewrite 规则。这非常简单。过滤一般的<tt>rewrite_rules_array</tt>。[http://vapourtrails.ca/wp-keywords Jerome's Keywords]插件执行这个操作,激活URLs,如<tt><nowiki>http://example.com/tag/sausages</nowiki></tt>。
 
<pre>
function keywords_createRewriteRules($rewrite) {
global $wp_rewrite;
// add rewrite tokens
$keytag_token = '%tag%';
$wp_rewrite->add_rewrite_tag($keytag_token, '(.+)', 'tag=');
$keywords_structure = $wp_rewrite->root . "tag/$keytag_token";
$keywords_rewrite = $wp_rewrite->generate_rewrite_rules($keywords_structure);
return ( $rewrite + $keywords_rewrite );
}
</pre>
 
 
 


<pre>
<pre>
第272行: 第136行:
</pre>
</pre>


Jerome没有将rewrite 规则插入到<tt>$rewrite</tt>数组,而是又创建了一个数组<tt>$keywords_rewrite</tt>,使用<tt>WP_Rewrite</tt> 函数<tt>generate_rewrite_rules()</tt>。使用那个函数,意味着这插件不需要为额外的网页(像<tt>page/2</tt>),或者feeds(像e <tt>feed/atom</tt>),等等创建rewrite规则。这个数组会附加到<tt>$rewrite</tt>数组上,并且会返回。


 
关于这个的一个简单的例子是Ryan Boren的[http://boren.nu/archives/2005/03/29/feed-director-plugin/ Feed Director]插件。这只是将URLs象http://example.com/feed.xml 导向了http://example.com/feed/rss2:
 
 
 
 
Instead of inserting the rewrite rules into the <tt>$rewrite</tt> array itself, Jerome chose to create a second array, <tt>$keywords_rewrite</tt>, using the <tt>WP_Rewrite</tt> function <tt>generate_rewrite_rules()</tt>. Using that function means that the plugin doesn't have to create rewrite rules for extra pages (like <tt>page/2</tt>), or feeds (like <tt>feed/atom</tt>), etc. This array is then appended onto the <tt>$rewrite</tt> array and returned.
 
Jerome没有将rewrite 规则插入到<tt>$rewrite</tt>数组,而是又创建了一个数组<tt>$keywords_rewrite</tt>,使用<tt>WP_Rewrite</tt> 函数<tt>generate_rewrite_rules()</tt>。使用那个函数,以为这插件不需要为额外的网页(像<tt>page/2</tt>),或者feeds(像e <tt>feed/atom</tt>),等等创建rewrite规则。这个数组会附加到<tt>$rewrite</tt>数组上,并且会返回。
 
A simpler example of this is Ryan Boren's [http://boren.nu/archives/2005/03/29/feed-director-plugin/ Feed Director] plugin. This simply redirects URLs like http://example.com/feed.xml to http://example.com/feed/rss2:
 
关于这个的一个简单的例子是Ryan Boren的[http://boren.nu/archives/2005/03/29/feed-director-plugin/ Feed Director]插件。这只是将URLs向http://example.com/feed.xml 导向了http://example.com/feed/rss2:
 


<pre>
<pre>
第301行: 第154行:
add_filter('generate_rewrite_rules', 'feed_dir_rewrite');
add_filter('generate_rewrite_rules', 'feed_dir_rewrite');
</pre>
</pre>
<pre>
function feed_dir_rewrite($wp_rewrite) {
    $feed_rules = array(
        'index.rdf' => 'index.php?feed=rdf',
        'index.xml' => 'index.php?feed=rss2',
        '(.+).xml' => 'index.php?feed=' . $wp_rewrite->preg_index(1)
    );
    $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
}
// Hook in.
add_filter('generate_rewrite_rules', 'feed_dir_rewrite');
</pre>
As the array is so simple here, there is no need to call <tt>generate_rewrite_rules()</tt>. Again, the plugin's rules are added to WordPress'. Notice that as this function filters <tt>generate_rewrite_rules</tt>, it accepts a reference to the entire <tt>$wp_rewrite</tt> object as a parameter, not just the rewrite rules.


因为这里的数组非常简单,没有必要调用<tt>generate_rewrite_rules()</tt>。同时,插件的规则添加到WordPress。注意因为这个函数过滤了<tt>generate_rewrite_rules</tt>,函数接受了整个<tt>$wp_rewrite</tt> object作为一个参数,而不仅仅rewrite 规则。
因为这里的数组非常简单,没有必要调用<tt>generate_rewrite_rules()</tt>。同时,插件的规则添加到WordPress。注意因为这个函数过滤了<tt>generate_rewrite_rules</tt>,函数接受了整个<tt>$wp_rewrite</tt> object作为一个参数,而不仅仅rewrite 规则。


Of course, as you're adding your rewrite rules to the array before WordPress does anything with them, your plugins rewrite rules will be included in anything WordPress does with the rewrite rules, like write them to the .htaccess file.
当然,因为你将你的rewrite规则添加到数组后,WordPress才能够处理这个规则,你的插件rewrite规则可能包含在WordPress处理rewrite规则的任何内容之中,象将其写入.htaccess文件一样。
 
当然,因为你将你的rewrite规则添加到数组后,WordPress才能够处理这个规则,你的插件rewrite规则可能包含在在WordPress处理rewrite规则的任何内容之中,向将其写入.htaccess文件。
 
== Non-Wordpress rewrite rules  ==


== 非Wordpress rewrite规则  ==
== 非Wordpress rewrite规则  ==
第348行: 第177行:
   </IfModule>
   </IfModule>
%%% <?php
$wp_rewrite->non_wp_rules = array( 'Pattern' => 'Substitution' );
print_r($wp_rewrite->mod_rewrite_rules());
?> %%%
prints
  <IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase <var>/wp_home/</var>
  RewriteRule ^Pattern <var>/wp_home/</var>Substitution [QSA,L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /<var>wp_home</var>/index.php [L]
  </IfModule>
where <var>/wp_home/</var> is Wordpress's home directory (or the root URL <tt>/</tt> if Wordpress is installed in your web root.)
<var>/wp_home/</var>是WordPress的主目录(如果WordPress安装在你的网络根目录上,是根URL <tt>/</tt>。)
<var>/wp_home/</var>是WordPress的主目录(如果WordPress安装在你的网络根目录上,是根URL <tt>/</tt>。)

2008年7月31日 (四) 18:08的最新版本

阅读这个文件的前提是,你熟悉Apachemod_rewrite。如果你从没有听说过这个,试着阅读Beginner's Guide to URL Rewriting

WP_Rewrite角色[ ]

WP_Rewrite是WordPress的class,用来管理rewrite 规则,使你能够使用Pretty Permalinks功能。从数据库中的参数值中产生rewrite 规则,有几种方法,当上传rewrite 规则的时候,是在内部使用的,同时查找某篇文章,某个网页,类别归档,等等的URL。定义在wp-includes/rewrite.php中而且一个全局singleton, $wp_rewrite,在wp-settings.php中初始化。

方法和属性[ ]

这是WP_Rewrite一个正式的文档。试着不要直接地访问或者设置属性,而是使用方法与$wp_rewrite object互动。

属性[ ]

$permalink_structure
数据库中的permalnk结构。这是你在Permalink选项网页上设置的内容,而且包含'标签' 像 %year%, %month% 和 %post_id%。
$category_base
在类别归档URLs之前插入的任何内容。默认为'类别/'。
$category_structure
类别归档URLs的结构。这只是$category_base和'%category%'。
$author_base
作者归档URLs之前插入的任何内容。默认为'作者/'。
$author_structure
作者归档URLs的结构。这只是$author_base和 '%author%'。
$feed_base
feed URLs之前插入的任何内容。默认为'feed/'。
$feed_structure
feed URLs的结构。这只是$feed_base 和 '%feed%'。
$search_base
searchs之前插入的任何内容。默认为'搜索/'。
$search_structure
搜索URLs的结构。这只是$search_base 和 '%search%'。
$comments_base
$feed_structure之前插入的任何内容,以得到最新的评论feed。默认为'评论'。
$comments_feed_structure
最新的评论feed的结构。这只是$comments_base$feed_base 和'%feed%'。
$date_structure
有日期的归档URLs的结构。试着为'%year%/%monthnum%/%day%', '%day%/%monthnum%/%year%' 或者 '%monthnum%/%day%/%year%',但是如果在你的$permalink_structure中没有发现这些,默认为'%year%/%monthnum%/%day%'。不同的函数使用这个结构得到更普通的结构:例如get_year_permastruct()这是从$date_structure中移除了'%monthnum%' 和 '%day%'标签。
$page_structure
网页结构。只是'%pagename%'。
$front
任何关于你的$permalink_structure第一个标签启动的内容。
$root
你的WordPress安装的根,是所有结构开始的地方。
$matches
当计算rewrite 规则的references的时候,在内部使用这个。
$rules
The rewrite rules. Set when rewrite_rules() is called.
$rules
rewrite规则。当调用rewrite_rules()时候,得到设置。
$non_wp_rules
Associative array of "rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all)" roughly in the form 'Pattern' => 'Substitution' (see below).
$non_wp_rules
"没有redirect to WP's index.php的规则 (因此不应该由WP处理)"的结合数组,基本形式是'Pattern' => 'Substitution'(请看看下面的)。
$rewritecode
An array of all the tags available for the permalink structure. See Using Permalinks for a list.
$rewritecode
permalink结构可以使用的所有标签的数组。请看看Using Permalinks的列表。
$rewritereplace
对于rewrite 规则的regex部分,每个标签会由什么取代。$rewritereplace中的第一个元素是$rewritecode中第一个元素的regex,第二个元素对应着第二个,等等。
$queryreplace
在rewrite规则的rewrite部分,每个标签会由什么来取代。在$rewritereplace中可以取代的部分,在这里也可以适用。

方法[ ]

add_rewrite_tag($tag, $pattern, $query)
$rewritecode, $rewritereplace$queryreplace添加一个元素,单独地使用每个参数。如果$rewritecode中已经存在$tag,当前的参数值就会被覆盖。
flush_rules()
重新产生rewrite规则,并将这个规则保存到数据库中。
generate_rewrite_rule($permalink_structure, $walk_dirs = false)
从permalink结构中产生不提供必要服务的rewrite规则。没有将要创建的额外网页或者feeds的规则。
generate_rewrite_rules($permalink_structure, $ep_mask = EP_NONE, $page =true, $feed = true, $forcomments = false, $walk_dirs =true)
一个很大的函数,为一个给定的结构$permalink_structure产生rewrite规则。如果$page 是true,会产生额外的rewrite 规则,来访问不同的网页(例如 /category/tech/page/2 指向'tech' 类别归档的第二个页面)。如果$feed 是true,会产生额外的rewrite规则,得到当前页面的feed,而且如果$walk_dirs 是true,那么会产生当前结构的每个目录的rewrite规则,例如,如果你提供 '/%year%/%month%/%day/', rewrite 规则会产生 '/%year%/', /%year%/%month%/' 和'/%year%/%month%/%day%/'。这返回了结合数组,使用rewrite 规则的regex部分作为keys,使用 redirect part of the rewrite 规则的redirect部分作为参数值。
get_date_permastruct(), get_category_permastruct(), get_date_permastruct()等等
在相关的属性上加上内容(例如$date_structure关于get_date_permastruct())。如果没有设置,将其返回。函数get_month_permastruct()get_year_permastruct()没有相关的属性:是通过获得$date_structure并且移除其不需要的标签(如get_month_permastruct() 移除了'%day%' 标签,因为其只要表明年份和月份)得到结构。
init()
设置object,从数据库中设置$permalink_structure$category_base。将$root设置为$index加上'/'。将$front设置为permalink结构中第一个标签开始的任何内容。取消所有其它属性。
mod_rewrite_rules()
返回所有规则的字符串(不是数组)。包含在Apache <IfModule> block,确保激活了mod_rewrite。
page_rewrite_rules()
返回你已经创建的任何网页的规则。
rewrite_rules()
generate_rewrite_rules()中那样,使用结合的数组填充并且返回$rules变数。这是从文章,日期,评论,搜索,类别,作者和网页结构中返回的。
set_category_base($category_base)
更改类别基础。
set_permalink_structure($permalink_structure)
更改permalink 结构。
using_index_permalinks()
如果你的博客使用PATHINFO permalinks,返回true
using_mod_rewrite_permalinks
如果你的博客通过mod_rewrite使用"pretty"permalinks,返回true
using_permalinks()
如果你的博客正在使用任何permalink结构(例如,不是默认的查询URIs ?p=n, ?cat=n),返回true
WP_Rewrite (构造器)
调用 init()
wp_rewrite_rules()
rewrite_rules(),返回rewrite规则的数组,但是使用$matches[xxx](xxx是个数字的位置),而不是普通的mod_rewrite backreferences,$xxx(xxx是个数字的位置)。当你准备在PHP内部使用规则的时候而不是在.htaccess文件中编写,这很有用。

插件Hooks[ ]

因为rewrite规则是你的网络博客泛函性的一个重要的方面,WordPress允许插件hook into几点的产生过程。rewrite_rules()包含有九个过滤器和一个hook来精确地控制rewrite规则的过程。下面是你可以在rewrite_rules()中过滤什么:

  • 要过滤为permalinks URLs产生的重写规则,请使用post_rewrite_rules
  • 要过滤为日期归档 URLs产生的重写规则,请使用date_rewrite_rules
  • 要过滤为类别归档 URLs产生的重写规则,请使用category_rewrite_rules
  • 要过滤为搜索 URLs产生的重写规则,请使用search_rewrite_rules
  • 要过滤为最近评论feed URLs产生的重写规则,请使用comments_rewrite_rules
  • 要过滤为作者归档 URLs产生的重写规则,请使用author_rewrite_rules
  • 要过滤为你的网页产生的重写规则,请使用page_rewrite_rules
  • 要过滤为你的网络日志根目录产生的重写规则,请使用root_rewrite_rules
  • 要过滤整个内容,请使用rewrite_rules_array
  • action hook generate_rewrite_rules在所有规则创建之后,才运行。如果你的函数获得一个参数,会得到reference传递到整个$wp_rewrite object。

mod_rewrite_rules()是个函数,获得rewrite_rules()产生的数组,而且将这个转变为.htaccess文件的rewrite规则。这个函数也有过滤器mod_rewrite_rules,会传递函数所有规则的字符串,为.htaccess编写,包含<IfModule>周围的部分。(注:你可能也会看到插件使用rewrite_ruleshook,但是这个已经取消了)。

例子[ ]

(也看看:自定义归档的Permalinks

插件处理$wp_rewrite 对象,典型的就是添加插件自身的rewrite 规则。这非常简单。过滤一般的rewrite_rules_arrayJerome's Keywords插件执行这个操作,激活URLs,如http://example.com/tag/sausages

function keywords_createRewriteRules($rewrite) {
	global $wp_rewrite;
	
	//添加rewrite记号
	$keytag_token = '%tag%';
	$wp_rewrite->add_rewrite_tag($keytag_token, '(.+)', 'tag=');
	
	$keywords_structure = $wp_rewrite->root . "tag/$keytag_token";
	$keywords_rewrite = $wp_rewrite->generate_rewrite_rules($keywords_structure);
	
	return ( $rewrite + $keywords_rewrite );
}

Jerome没有将rewrite 规则插入到$rewrite数组,而是又创建了一个数组$keywords_rewrite,使用WP_Rewrite 函数generate_rewrite_rules()。使用那个函数,意味着这插件不需要为额外的网页(像page/2),或者feeds(像e feed/atom),等等创建rewrite规则。这个数组会附加到$rewrite数组上,并且会返回。

关于这个的一个简单的例子是Ryan Boren的Feed Director插件。这只是将URLs象http://example.com/feed.xml 导向了http://example.com/feed/rss2:

function feed_dir_rewrite($wp_rewrite) {
    $feed_rules = array(
        'index.rdf' => 'index.php?feed=rdf',
        'index.xml' => 'index.php?feed=rss2',
        '(.+).xml' => 'index.php?feed=' . $wp_rewrite->preg_index(1)
    );

    $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
}

// Hook in.
add_filter('generate_rewrite_rules', 'feed_dir_rewrite');

因为这里的数组非常简单,没有必要调用generate_rewrite_rules()。同时,插件的规则添加到WordPress。注意因为这个函数过滤了generate_rewrite_rules,函数接受了整个$wp_rewrite object作为一个参数,而不仅仅rewrite 规则。

当然,因为你将你的rewrite规则添加到数组后,WordPress才能够处理这个规则,你的插件rewrite规则可能包含在WordPress处理rewrite规则的任何内容之中,象将其写入.htaccess文件一样。

非Wordpress rewrite规则[ ]

%%% <?php $wp_rewrite->non_wp_rules = array( 'Pattern' => 'Substitution' ); print_r($wp_rewrite->mod_rewrite_rules()); ?> %%%

prints

 <IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /wp_home/
 RewriteRule ^Pattern /wp_home/Substitution [QSA,L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /wp_home/index.php [L]
 </IfModule>

/wp_home/是WordPress的主目录(如果WordPress安装在你的网络根目录上,是根URL /。)