I want to have the .html extension in the custom post type taxonomy urls. My custom post type taxonomy it is called "product_cat". I will need something like:


Tried this one, inserting in functions.php, without success:

add_action('init', 'add_html_ext_to_custom_post_type_taxonomies');
function add_html_ext_to_custom_post_type_taxonomies() {
    add_rewrite_rule('^product_cat/([^/]+)\.html', 'index.php?product_cat=$matches[1]', 'top');

Further tries:

Also I've used the Custom Post Type Permalink plugin and have played around line 559. Replaced the code from line 559 to line 561 with the next one:

$termlink = str_replace( $wp_home, $wp_home, $termlink );
$str = rtrim( preg_replace("/%[a-z_]*%/","",get_option("permalink_structure")) ,'/');//remove with front
return str_replace($str, "", $termlink.'.html' );

This will return the .html in the taxonomy view page url, but it gives a 404.

  • Just wondering, why? Is it for SEO? If yes, you should really do a 301 redirect to the proper page. – David Kryzaniak Jul 26 '13 at 2:41
  • It is just a request from a friend. Don't know his reasons. This must be done dynamically. – Grávuj Miklós Henrich Jul 28 '13 at 14:24

I've tested your first attempt with using a rewrite rule it works

add_action('init', 'add_html_ext_to_custom_post_type_taxonomies');
function add_html_ext_to_custom_post_type_taxonomies() {
    add_rewrite_rule('^product_cat/(.+)\.html', 'index.php?product_cat=$matches[1]', 'top');

but you have _ not - had you noticed this as you give your example as www.mydomain.com/product-category/product-category-name.html

If its not a mistake it might be you have another rule conflicting with it? and also have you flushed the rules? You could check using the Rewrite Rules Inspector plugin and also you can use it to flush the rules if you haven't already done so.

  • Thank you for your effort and help. Yeah, I haven't seen the wood because of a tree :) It works now also for me like this: add_rewrite_rule('^product-category/([^/]+)\.html', 'index.php?product_cat=$matches[1]', 'top'); One single issue: subcategories are returning a 404 – Grávuj Miklós Henrich Jul 29 '13 at 14:15
  • Is there a separate parameter for sub categories or is it just product_cat=subcategory? – Mark Davidson Jul 29 '13 at 14:20
  • The same parameter also for sub categories, product_cat. – Grávuj Miklós Henrich Jul 29 '13 at 14:21
  • Can you give me an example of a subcategory your testing with? Might be something to do with that subcategory conflicting with another rule. – Mark Davidson Jul 29 '13 at 14:48
  • http://www.mydomain.com/product-category/parent-product-category/sub-category.html from where product-category is the category base, as it shows also above in the desc. – Grávuj Miklós Henrich Jul 29 '13 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.