I have seen quite a few questions on here asking around the same thing but either have been unanswered or slightly different!
I have tested the following on a linux machine and all works fine, when I transfer it to windows to run under iis7 it breaks. So I know its setup right as far as the post type and taxonomy code goes.
I create a product(my custom post type) and have the following as product categories(custom taxonomy):
– test1
— test2
— test3
—- test 4
I assign the product to the test 4 category. So on my linux machine http://localhost/products/test1/test2/test3/test4/product-1/
works perfect. On IIS7 it breaks BUT if I assign the product to the test 1 category it works so:
http://localhost/products/test1/product-1/
I am using the ‘Custom Post Type Permalinks’ plugin and have my posttype permalink set to:
‘/%product_categories%/%postname%/’
Here is my web.config file:
<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>
Any ideas would be great!
— Edit —
I also just tried this http://localhost/products/test4/product-1/
and it worked. So its just not liking the parent categories.
Finally figured out the answer. It is a mix of multiple different solutions I have found online but here it is!
First step is to add this to your functions.php
Secondly you will need this in your web.config
<?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>
Lastly here is how I have my custom post type and taxanomy setup. Replace “yourid” with whatever you want to make sure you dont have any issues with other plugins.
If you have any issues or need assistance let me know!