views:

49

answers:

3

I wanna turn PHP dynamic URLs into static URLs. For example, I want URLs like

http://www.example.com/book.php?title=twilight to become http://www.example.com/book/twilight

and http://www.example.com/writer.php?name=meyers to become http://www.example.com/writer/meyers

When it's done, will my form validation on the site change?

My URL rewriting needs might not be much too complicated.

I'm developing it locally using XAMPP, Apache and MySql. Later I'll put it online.

How do I do that? Is this kind of URL rewriting technique the most adviced for SEO?

+2  A: 

You would use mod_rewrite for that. If you do a bit of searching on here for that, you'll likely find lots of other questions about how to create mod_rewrite rules similar to what you want to do.

Eric Petroelje
+1  A: 

Yep. U need to use mod_rewrite. Also do a search for .ht_access files. You can put your rewrite directives in .ht_access files and drop them in to whatever directory on your server where you want them to take effect.

For the type of rewrite you want this rule generator should be of use to you:

http://www.generateit.net/mod-rewrite/

And yes the URL you're trying to achieve is seo friendly.

elduderino
Usually, the file is called `.htaccess` with no underscore, and it's usually more efficient if you can include your mod_rewrite directives in your apache conf.
grossvogel
I mentioned .htaccess because lots of people don't have access to httpd.conf. Thanks for the correction ;)
elduderino
A: 

You can use a .htaccess file (or better apache.conf) to forward all requests to index.php with mod_rewrite:

Options +FollowSymLinks
IndexIgnore */*

<ifmodule mod_rewrite.c> 
RewriteEngine on

    # if a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # otherwise forward it to index.php
    RewriteRule . index.php
</ifmodule>

There you can use $_SERVER['REQUEST_URI'] to interpret the request.

Sven Walter
"There you can use $_SERVER['REQUEST_URI'] to interpret the request." How is that?
Rafael Carvalho
If your request is `http://www.example.com/writer/meyers`, than `$_SERVER['REQUEST_URI']` is `/writer/meyers`. You can interpret it with Regex or by simply splitting string: `explode('/',$_SERVER['REQUEST_URI']);`.
Sven Walter