0

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?

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

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.
I mentioned .htaccess because lots of people don't have access to httpd.conf. Thanks for the correction ;)
1

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.

2 Comments

"There you can use $_SERVER['REQUEST_URI'] to interpret the request." How is that?
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']);.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.