Permalinks

I have a database which holds an id, title and link
the link is actually the embed code from a youtube video

this is my code to link to the video
<?php echo “<a href=\“videos.html?id=$id\”>$title</a>”;

when the page loads it shows "localhost/websites/sitea/videos.html?id=1

how do i make it so the ?id=1 dissapears and is replaced with the $title instead, i cant just use $title for the link incase the title is repeated somewhere
so i want the url to look like this please

localhost/websites/sitea/videos/youtubevideoname or
localhost/websites/sitea/videos/youtubevideoname.html

Use the title and a date to make them more likely to be unique, and enforce uniqueness in the table.

Add a field “permalink” and do some simple string manipulation to turn My Little Pony Video into “my-little-pony-video” and store that in the permalink (or slug, I have seen it termed).

Then read up on apaches mod_rewrite - this is a good tut :

mod_rewrite: A Beginner’s Guide to URL Rewriting Article » SitePoint

and so is this:

Apache’s mod_rewrite

If you need others then ask.

yes i will be adding date, just forgot it so far but is there no way to do this just with using different variables rather than mode rewrites?
Also are there any other full tutorials somewhere?

Without mod_rewrite you’ll always need the query string in the URL, such as ?video=my-little-pony

ok so are there any simple tutorials out there that can help me
in the db il have id, title, link(which is the embed code), date and permalink

what code changes the title “song title a” to “song-title-a.html”
and what must then be done in the permalinks or mod rewrite


function mk_link($title) {
  $link = strtolower($title);
  $link = preg_replace('/ +/', '-', $link); //spaces to dashes
  $link = preg_replace('/[^a-z0-9,\\.\\_\\-]/', '', $link); //remove non-std characters

  return $link;
}

Pass your title into that. You’ll need to check it’s unique in the DB, or append the date.

Your Rewrite Rule will look something like this:


RewriteEngine On
RewriteRule videos\\/([^a-z0-9,\\.\\_\\-]+)/?$ videos.html?permalink=$1

Then videos.html (which will need to be able to execute PHP!) will have $_GET[‘permanlink’] which can be used to call the DB.