99% of WooCommerce users would prefer to use beautiful permalinks/slugs for WooCommerce product pages. But also for category pages!
We need a nice plugin : Remove slug from custom post type and some tricks.
After installing this plugin, we go to its settings page:
Click the Save Changes button, your Woocommerce product page permalinks are now :
If you want .html instead of / , simply type in html and save changes.
Now your product page slug should be :
In many cases, this plugin works like a charm, but sometimes it won’t work, especially in latest version of WordPress, as you can see, this plugin is not updated for 2 years….
The most typical problem is :
for old products, the slugs were changed successfully, but we can’t create new products, we would encounter 404 error when opening new product pages !
The solution is simple and quite funny:
Just set the publish time to some time long ago, today is 10th Jan. 2014, I set the publish time to 2013. Save it, your product were now “published long ago”, and you will be able to open the page, no 404 error anymore.
Another typical problem is that:
This plugin applies to all custom post type by default, we can’t exclude it from some other custom post types, like Portfolio (many themes have this sort of custom post type). So solve this, open the .htaccess file on root folder on your site.
# BEGIN REMOVE SLUG CUSTOM POST TYPE RULES RewriteRule ^product /(.+)/$ /$1 [R=301,L] RewriteRule ^product_variation/(.+)/$ /$1 [R=301,L] RewriteRule ^/(.+)/$ /$1 [R=301,L] RewriteRule ^/(.+)/$ /$1 [R=301,L] RewriteRule ^portfolio/(.+)/$ /$1 [R=301,L] # END REMOVE SLUG CUSTOM POST TYPE RULES
As you can see, there are many rules for other custom post types, like product_variation and portfolio. I would like to disable url rewritten for them. So I removed them, this code block becomes:
# BEGIN REMOVE SLUG CUSTOM POST TYPE RULES RewriteRule ^product /(.+)/$ /$1 [R=301,L] # END REMOVE SLUG CUSTOM POST TYPE RULES
Note: Don’t remove the 1st and last 2 lines which begins with #