When you edit a question on stackoverflow.com, you will be redirected to a URL like this:
But usually, it should be
or
How was
I know that Stackoverflow.com was not created by using PHP, but I am wondering how to achieve this in PHP?
When you edit a question on stackoverflow.com, you will be redirected to a URL like this:
But usually, it should be
or
How was
I know that Stackoverflow.com was not created by using PHP, but I am wondering how to achieve this in PHP?
It's called routing. Take a look at tutorials on the subject.
If you use a framework such as cake php it should be built in.
As @mr-euro stated you can use mod_rewrite but front controller is a far better solution. You force every request to index.php and you write your application controlling in index.php.
You use Apache's .htaccess/mod_rewrite, and optionally a PHP file, which is the approach I like to take myself.
For the .htaccess, something like this:
Then in your PHP file, you can do something like this:
The following should get everything after the first slash.
You can then use explode to turn it into an array.
Now you can use the array to determine what to load:
The array is starting from 1 since 0 will usually be empty.
You could use htaccess + write an URI parser class.
I am poor at this but i do know you can redirect urls using apache mod_rewrite and by touching config files. From what i remember htaccess can be used to redirect. Then internally when the user hits
http://stackoverflow.com/posts/1807421/edit
it can use your pagehttp://stackoverflow.com/edit.php?p=1807421
instead or whatever you want.It's indeed done by mod_rewrite, or with multiviews. But i prefer mod_rewrite.
First: you create a .htaccessfile with these contents:
Obvious, mod_rewrite must be enabled by your hostingprovider ;)