IIS 7使用父类别重写

时间:2014-03-31 作者:Silent

我在这里看到了很多关于同一件事的问题,但要么没有答案,要么略有不同!

我在linux机器上测试了以下内容,一切正常,当我将其传输到windows以在iis7下运行时,它会崩溃。因此,我知道它的设置,就文章类型和分类代码而言。

我创建了一个产品(我的自定义帖子类型),并将以下内容作为产品类别(自定义分类法):
-test1
-test2
-test3
-test4

我将产品分配到测试4类别。所以在我的linux机器上http://localhost/products/test1/test2/test3/test4/product-1/ 工作完美。在IIS7上,它会断裂,但如果我将产品分配到测试1类别,它会工作:http://localhost/products/test1/product-1/

我正在使用“自定义Post-Type Permalinks”插件,并将我的posttype permalink设置为:“/%product\\u categories%/%postname%/”

这是我的网站。配置文件:

<configuration>
  <system.webServer>
    <rewrite>
    <rules>
        <rule name="Main Rule" stopProcessing="true">
            <match url=".*" />
            <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Rewrite" url="index.php" />
        </rule>
    </rules>
   </rewrite>
  </system.webServer>
</configuration>
任何想法都会很好!

--编辑--我也试过这个http://localhost/products/test4/product-1/ 它成功了。因此,它只是不喜欢父类别。

1 个回复
SO网友:Silent

终于找到了答案。这是我在网上找到的多种不同解决方案的组合,但它就在这里!

第一步是将其添加到函数中。php

add_rewrite_rule(
    \'products/([^/]+)/([^/]+)/?\',       
    \'index.php?pmfg_product_categories=$matches[1]&products=$matches[2]\',      
    \'top\'
);
其次,你需要在你的网站上使用它。配置

<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules><rule name="WordPress Rule" stopProcessing="true"><match url=".*"/><conditions><add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/><add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/></conditions><action type="Rewrite" url="index.php?page_id={R:0}"/></rule> <rule name="wordpress" patternSyntax="Wildcard"> <match url="*"/> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/> </conditions> <action type="Rewrite" url="index.php"/> </rule></rules> </rewrite> </system.webServer> </configuration>

最后,这里是我如何有我的自定义帖子类型和分类设置。将“yourid”替换为您想要的任何内容,以确保您与其他插件没有任何问题。

// Register Custom Post Type
function yourid_product_tax_type(){
    $labels = array(
        \'name\'                       => _x( \'Product Categories\', \'Taxonomy General Name\', \'text_domain\' ),
        \'singular_name\'              => _x( \'Product Category\', \'Taxonomy Singular Name\', \'text_domain\' ),
        \'menu_name\'                  => __( \'Product Categories\', \'text_domain\' ),
        \'all_items\'                  => __( \'All Product Categories\', \'text_domain\' ),
        \'parent_item\'                => __( \'Parent Category\', \'text_domain\' ),
        \'parent_item_colon\'          => __( \'Parent Category:\', \'text_domain\' ),
        \'new_item_name\'              => __( \'New Product Category Name\', \'text_domain\' ),
        \'add_new_item\'               => __( \'Add New Product Category\', \'text_domain\' ),
        \'edit_item\'                  => __( \'Edit Product Category\', \'text_domain\' ),
        \'update_item\'                => __( \'Update Product Category\', \'text_domain\' ),
        \'separate_items_with_commas\' => __( \'Separate categories with commas\', \'text_domain\' ),
        \'search_items\'               => __( \'Search Product Categories\', \'text_domain\' ),
        \'add_or_remove_items\'        => __( \'Add or remove product categories\', \'text_domain\' ),
        \'choose_from_most_used\'      => __( \'Choose from the most used product categories\', \'text_domain\' ),
        \'not_found\'                  => __( \'Product Category Not Found\', \'text_domain\' ),
    );
    $args = array(
        \'label\' => \'Product Categories\',
        \'labels\'                     => $labels,
        \'hierarchical\'               => true,
        \'public\'                     => true,
        \'show_ui\'                       => true,
        \'show_in_nav_menus\'             => true,
        \'args\'                          => array( \'orderby\' => \'term_order\' ),
        \'rewrite\'             => array(
                \'slug\' => \'test\',
                \'with_front\'=>true,                 
            ),
        \'query_var\'                     => true,
    );
    register_taxonomy( \'yourid_product_categories\', array(), $args );
}
add_action( \'init\', \'yourid_product_tax_type\', 0 );

function yourid_post_type() {       
    $labels = array(
        \'name\'                => _x( \'Products\', \'Post Type General Name\', \'text_domain\' ),
        \'singular_name\'       => _x( \'Product\', \'Post Type Singular Name\', \'text_domain\' ),
        \'menu_name\'           => __( \'Products\', \'text_domain\' ),
        \'parent_item_colon\'   => __( \'Parent Product: \', \'text_domain\' ),
        \'all_items\'           => __( \'All Products\', \'text_domain\' ),
        \'view_item\'           => __( \'View Product\', \'text_domain\' ),
        \'add_new_item\'        => __( \'Add New Product\', \'text_domain\' ),
        \'add_new\'             => __( \'Add New\', \'text_domain\' ),
        \'edit_item\'           => __( \'Edit Product\', \'text_domain\' ),
        \'update_item\'         => __( \'Update Product\', \'text_domain\' ),
        \'search_items\'        => __( \'Search Product\', \'text_domain\' ),
        \'not_found\'           => __( \'Product Not Found\', \'text_domain\' ),
        \'not_found_in_trash\'  => __( \'Product not found in Trash\', \'text_domain\' ),
    );
    $rewrite = array(
        \'slug\'                => \'products\',
        \'with_front\'          => true,
        \'pages\'               => true,
        \'feeds\'               => true,
    );
    $args = array(
        \'label\'               => __( \'yourid_product\', \'text_domain\' ),
        \'description\'         => __( \'YourName Products\', \'text_domain\' ),
        \'labels\'              => $labels,           
        \'taxonomies\'          => array( \'yourid_product_categories\' ),
        \'hierarchical\'        => true,
        \'public\'              => true,
        \'show_ui\'             => true,
        \'show_in_menu\'        => true,          
        \'has_archive\'         => true,
        \'exclude_from_search\' => false,
        \'publicly_queryable\'  => true,
        \'rewrite\'             => array(
            \'slug\'=>\'products\',
            \'with_front\'=>false,
        ),
        \'capability_type\'     => \'page\',
    );
    register_post_type( \'yourid_product\', $args );      
}

// Hook into the \'init\' action
add_action( \'init\', \'yourid_post_type\', 0 );
如果您有任何问题或需要帮助,请告诉我!

结束

相关推荐

Pretty Permalinks

我创建了自己的搜索功能,基本上可以找到与输入的邮政编码最近的商店。我的搜索URL当前如下所示http://www.example.com/stores?searchTerm=London, 这并不是真正的SEO友好。我希望我的URL采用以下格式-http://www.example.com/stores/London, 然而,由于我缺乏WordPress URL重写工作的知识,我正在努力解决这个问题,希望能得到一些帮助来解决这个问题。Stores是一个循环显示结果的页面。如果有人对如何做到这一点有任何想法