0

I have a DB table that saves my title as a slug (ie: this-is-my-title-slug) but I have no clue how to use it in the url.

Example ofor current url http://www.example.com/post.php?id=102

What I want is http://www.example.com/this-is-a-slug.

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47

1 Answers1

1

You're looking at SEO urls. And a slug is something you would use as a name of an article on www.example.com/articles/article-title-slug for instance, what you probably mean is a permalinks which basically are SEO urls.

If you're running an apache server with PHP and you have a vhost setup then you can use that vhost to allow url rewriting (Apache mod_rewrite).

This allows you to place a file called .htaccess in the webroot of your project (e.g. same directory as root index.php file), within this file you can set up rules that allow such rewriting. What often happens is that you rewrite everything to the root index.php file and you capture the URI and parse the parameters by splitting it on the forward slash (/) character. This is basically a router idea.

The advantage of parsing the URI yourself is that you don't really have to do much in the .htaccess file which is much more complex to handle than building a router in PHP itself as well.

A good example of a .htaccess file can be found on this SO answer

about how to get going with that. There are also plenty of other tutorials to get started with this other than that answer.

It's been a while since I've done it myself but if you have questions, just ask them and I'll see if I can help but anyways, this should point you in the right direction.

Community
  • 1
  • 1
SidOfc
  • 4,552
  • 3
  • 27
  • 50