I am trying to implement URL rewriting in my PHP application. Can someone share a step by step procedure of implementing URL rewriting in PHP and MySQL?
In my application I want to implement following URL rewriting, I want to redirect
1. http://example.com/videos/play/google-io-2009-wave-intro
2. http://example.com/videos/play/203/google-io-2009-wave-intro
to
1. http://example.com/videos/play.php?title=google-io-2009-wave-intro
2. http://example.com/videos/play.php?id=203
Please tell me how to implement both URL rewriting in any of the above way.
One more thing which URL will be best according to SEO, management, application point-of-view out of the following two types.
1. http://example.com/videos/play/google-io-2009-wave-intro
2. http://example.com/videos/play/203/google-io-2009-wave-intro
Using mod rewrite:
example.com/play.php?id=203&name=google-io-2009-wave-intro
would work as
example.com/videos/play/203/google-io-2009-wave-intro
If your server supports it (apache / mod_rewrite), you can use a .htaccess file to re-direct the visitor.
Something like (just a draft, adapt to your own needs...):
for the second example.
Sorry about not giving you detailed explanation, but maybe you could take a look at DokuWiki for a starting point.
In its setup it accepts 3 modes:
It's free so you can just download and browse the code.
As a note, the apache redirect is very likely the best solution but the pure php one is also interesting in case your code is going to run in IIS6 servers where rewritting is not as easy as in apache.