Hi there, welcome to the forums! Good question (and err interesting name as well!!)
You are right, you can indeed change your URLs without physically changing the location of your pages - as you say this has some SEO benefit, by increasing keyword density in the URL, but also a massive usability benefit. Consider pages like profile.php?id=1243438729. I'm never going to remember that that's where my profile is, but on the other hand, site.com/profile/bigalreturns is no problem to remember. Also, it's logical how I would go to another user's profile.
In your case, I wouldn't expect massive SEO benefits, as you already have the page keyword in the URL, expect a bigger benefit when changing, for example, IDs to names. Even so, my policy on SEO is every little helps, and perhaps you can apply this technique to other pages/sections of your site.
The technique we're going to use is called mod_rewrite, and it's a feature of Apache servers - I assume that as you're using PHP then this is what your server runs on. Microsoft IIS server has an equivalent, but let's not worry about that - you're very unlikely to be on an IIS server unless you specifically looked to get on one.
So what do we do - we need to edit/create a file in the root directory of the site, called .htaccess - thats no actual filename, just the extension .htaccess. It probably already contains some information, leave this as it is and start a line or so below this with the code. Firstly, we need to turn on the mod_rewrite feature, which is done with these two lines:
Code:
Options +FollowSymLinks
RewriteEngine on
After this, what we are going to use is a regular expression, which Apache will match against the typed in URL, and if it matches, apply the rule, and show the content from the page we specify. Regex is a complex subject, and I can't explain it here, but do some reading around, and try and adapt something to your needs. You can always come and post back here if you're struggling!
So in this case, the URLs we want to match are of the following structure:
mysite.com/xxxxxxx
The xs are the part that's important, as that's what determines which pages is shown. The regular expression to match this is as follows, it starts with ^ and ends with $, these are just to show the start and end of the expression.
Code:
^/?([a-zA-Z0-9])/?$
A little explanation of what's going on. The [square brackets] represent character sets, in this case we want to include a-z, A-Z and 0-9, i.e. all upper and lower case letters, and all numbers. The (round brackets) group things together - in this case we're grouping the bit typed in by the user, so we can use it later. Question marks mean the preceding string may or may not be there. We use it on the leading slash because different Apache versions may or may not use this in the matching string. The trailing slash is optional, because the user may or may not decide to type it in.
The clever part is now - each set of brackets is then passed to the next part of the string. The first set of bracket's content is represented by $1, the second set by $2 and so on. The order is by
opening brackets by the way - can get confusing. So we can now write the second part of our rule, which tells Apache where the page actually is:
So if we type in page.com/music/, apache recognises the /music/ as conforming to our rule, sends "music" as $1 to the second part, and fetches the page index.php?page=music.
We have all we need to create our rule now, we just need to define it as a rule by starting the line with RewriteRule. The order of parts to the rule is shown in the complete code below:
Code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/?([a-zA-Z0-9])/?$ index.php?page=$1
So now we can (hopefully) type in mysite.com/music, and while that address stays in the address bar, the content shown is actually from mysite.com/index.php?page=music.
mod_rewrite is a very powerful tool, so do some more reading about it, experiment, and come back here with any problems! Good luck!