10 Replies
i see in some website for make online profile they do something so everyone can make a account with unique username and they can serch for their account in url with the user name like this
https://x.com/[ any name ]
how this is possible ?
the most common way is to use
mod_rewrite
in apache, which lets you rewrite the URL from the request after it hits the server but before it's processed
nginx has a similar system
You can either set it all up in your webserver, or have mod_rewrite
redirect all traffic to a router in your application, which then does its magic to load and display the correct page.so this mod_rewrite will edit only url right ?
but it send the user in another loction
it rewrites the URL internally, the user doesn't see the change
so for example while you see x.com/nima, the server sends the request to x.com/user.php?username=nima
ohh now it make sense
is it possibel to use it in php ? mod_rewrit
you mean using the builtin PHP server? Not really, afaik
so only way is with apache
not quite
there's other ways to accomplish this. Another common way is to use a router script, and mod_rewrite (or use some other method) to send all traffic to the router script. You can do that with php's internal server too
I generally prefer to use apache in dev environments too though, mostly cause you can use mod_rewrite and other .htaccess directives
tnx i will try apache