Normally, the practice or very old way of displaying some profile page is like this:
www.domain.com/profile.php?u=12345
where u=12345
is the user id.
In recent years, I found some website with very nice urls like:
www.domain.com/profile/12345
How do I do this in PHP?
Just as a wild guess, is it something to do with the .htaccess
file? Can you give me more tips or some sample code on how to write the .htaccess
file?
ModRewrite is not the only answer. You could also use Options +MultiViews in .htaccess and then check
$_SERVER REQUEST_URI
to find everything that is in URL.According to this article, you want a mod_rewrite (placed in an
.htaccess
file) rule that looks something like this:And this maps requests from
to
Another possibility is doing it with
forcetype
, which forces anything down a particular path to use php to eval the content. So, in your.htaccess
file, put the following:And then the index.php can take action based on the
$_SERVER['PATH_INFO']
variable:Simple way to do this. Try this code. Put code in your
htaccess
file:It will create this type pretty URL:
For more htaccess Pretty URL:http://www.webconfs.com/url-rewriting-tool.php
I recently used the following in an application that is working well for my needs.
.htaccess
index.php
It looks like you are talking about a RESTful webservice.
http://en.wikipedia.org/wiki/Representational_State_Transfer
The .htaccess file does rewrite all URIs to point to one controller, but that is more detailed then you want to get at this point. You may want to look at Recess
It's a RESTful framework all in PHP
It's actually not PHP, it's apache using mod_rewrite. What happens is the person requests the link, www.example.com/profile/12345 and then apache chops it up using a rewrite rule making it look like this, www.example.com/profile.php?u=12345, to the server. You can find more here: Rewrite Guide