Search code examples
php.htaccessurl-rewritingsubdirectoryepiserver

Rewrite Subdirectory to URL String with Episerver Platform


I need to create a rule that will change a subdirectory to part of the url string by replacing the "/" with "-". The product id number was added to the end of all URLs to avoid having duplicate URLs, but it should not be in its own folder. The platform is Episerver. Here is an example:

www.example.com/products/blue-toy/2324

www.example.com/products/hair-spray/3374

to

www.example.com/products/blue-toy-2324

www.example.com/products/hair-spray-3374

Solution

  • You can use this rule as your very first rule in your root .htaccess:

    RewriteEngine On
    
    RewriteRule ^(products)/([^/]+)/([0-9]+)/?$ /$1/$2-$3 [L,NC,R=302]