htaccess rewrite slug to seo url

.htaccess, mod-rewrite, php, url-rewriting

Solution

Use:

RewriteEngine On
RewriteRule ^works/(.*)$ works/show.php?slug=$1 [L]

You can also put your .htaccess file into works folder with this code:

RewriteEngine On
RewriteRule ^(.*)$ show.php?slug=$1 [L]

Problem

I have some URLs like this: www.mydomain/works/show.php?slug=title-of-the-work I'll like to have htaccess convert to seo URLs in this way: www.mydomain/works/title-of-the-work In my database I have created a field called slug for every work entry. The first URL works fine. This is how my .htaccess currently looks (it is placed in my root directory): ``` RewriteEngine On RewriteRule /works/(.*)$ /works/show.php?slug=$1 ``` I've read and tried a lot of similar examples during the last 24hours to no avail. I'm sure my server allows rewriting, because I can for example rewrite non-www to www URLs. Hope someone can help. Thanks

Original source