I'm creating a website using PHP and Apache. I wanna turn my Web addresses from

world wide web.example.com/book.php?book=title

into something similar to this, if it's possible obviously:

world wide web.example.com/book/title

Observe that the title from the books are unique and can't be repeated.

I`ve find out about this, but no posts were obvious enough for any beginner much like me. Do everyone know any tutorial that describes that?


The feature you are searching for is known as 'url spinning".

It can be done by hand : you explain the pattern using regular expression, and also the webserver translates the demands. With Apache it's generally found under htaccess files, or directyl within the httpd.conf. see official doc. here : http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

It isn't "that" simple to setup though, debugging regular expressions particularly.

Relating to your problem, consider using a rule such as this :

RewriteEngine on 
RewriteRule ^book/(.*)$ book.php?book=$1 [L]

An alternative choice, is always to make use of a php framework : the majority of time, this feature is made-in. You need to "learn" though ways to use the framework. If your site is already finished, this isn't the best choice...

Here's the way in which kohana (and 99.99% of php frameworks) will it

Add an .htaccess file(if using apache)

# Turn on URL rewriting
RewriteEngine On

RewriteBase /

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]

This redirects all web addresses to index.php. index.php is going to be some kind of front controller that loads scripts in line with the url

So inside your example:


index.php could be loaded. It might enter in the url and obtain the page (controller) to load which will really do everything. within this situation maybe books.php. books.php would obtain the title from the book in the url after which search a database or do whatever it needs to with this title.

Most solutions depend on mod_rewrite. See here for good examples.