Dynamic URLs without creating .html for each user

I am working on a website like oc.tc. Site system, not content. In any case, if you notice how you can do oc.tc/itunes89(Or oc.tc/anyregistereduser), I would like to know how to do it. I don’t think that pages are created for everyone there, I think that it does it dynamically there.

* I already created a system, for example username = user and id = 12. I would like to know how to do this without causing a 404 error.

Thank you for your help.

+4
source share
2 answers

Are you using Apache?

If so, welcome to the wonderful world of Apache mod_rewrite. ( http://httpd.apache.org/docs/current/mod/mod_rewrite.html )

Here's the basic concept: you define rules that "rewrite" URLs, such as oc.tc/itunes89 , in oc.tc/show_user.php?username=itunes89 (or whatever you want).

This is a great guide to mod_rewrite: http://www.sitepoint.com/guide-url-rewriting-2/ . Let me know if you have a specific question or problem with its implementation.

+2
source

For Apache Tomcat, you can do such things if you map the servlet to a specific URL pattern and then display the correct page. A tutorial showing an example can be found here . Together with the JSPServlet source code ( here ), you can build your own servlet that does what you want. I think the method used to extract the path is HttpRequest.getServletPath () and HttpRequest.getPathInfo (), but it’s best to try to understand the source code that I pointed to (the service method (..) is the one that is called when you get access to the servlet).

+1
source

All Articles