Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess rewrite slug to seo url

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

like image 868
user2735267 Avatar asked Oct 15 '25 14:10

user2735267


1 Answers

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]
like image 92
Lkopo Avatar answered Oct 18 '25 17:10

Lkopo