动态URL而不为每个用户创建.html

时间:2021-07-24 13:17:27

I'm working on creating a website similar to oc.tc. The website system, not the content. Anyway, if you notice how you can do oc.tc/itunes89(Or oc.tc/anyregistereduser) I would like to know how to do that. I don't think there creating pages for everyone, I think there dynamically doing this.

我正在创建一个类似于oc.tc的网站。网站系统,而不是内容。无论如何,如果你注意到如何做oc.tc/itunes89(或oc.tc/anyregistereduser)我想知道如何做到这一点。我认为没有为每个人创建页面,我认为有动态这样做。

*I've already created a system, like username=user and id=12. I would like to know how to do that without triggering a 404 error.

*我已经创建了一个系统,比如username = user和id = 12。我想知道如何在不触发404错误的情况下执行此操作。

Thanks for your help.

谢谢你的帮助。

2 个解决方案

#1


2  

Are you using Apache?

你在使用Apache吗?

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

如果是这样,欢迎来到Apache的mod_rewrite令人惊叹的世界。 (http://httpd.apache.org/docs/current/mod/mod_rewrite.html)

Here's the basic concept: you define rules that "rewrite" a URL like oc.tc/itunes89 into oc.tc/show_user.php?username=itunes89 (or whatever you want).

这是基本概念:您可以定义将oc.tc/itunes89等URL“重写”为oc.tc/show_user.php?username=itunes89(或任何您想要的)的规则。

This is an excellent guide to mod_rewrite: http://www.sitepoint.com/guide-url-rewriting-2/. Let me know if you have a specific question or problem implementing it.

这是mod_rewrite的优秀指南:http://www.sitepoint.com/guide-url-rewriting-2/。如果您有实施它的具体问题或问题,请告诉我。

#2


1  

For Apache Tomcat, you can do such things if you map a servlet to a certain URL pattern, and then show the correct page. A tutorial that shows an example can be found here. Together with the source code of the JSPServlet ( here ), you can put together your own servlet that does what you want. I think the method used to retrieve the path is HttpRequest.getServletPath() and HttpRequest.getPathInfo(), but you best just try to understand the source code i pointed to (the service(..) method is the one that is called when you access the servlet).

对于Apache Tomcat,如果将servlet映射到某个URL模式,然后显示正确的页面,则可以执行此类操作。可以在此处找到显示示例的教程。与JSPServlet的源代码(此处)一起,您可以将自己的servlet放在一起,完成您想要的操作。我认为用于检索路径的方法是HttpRequest.getServletPath()和HttpRequest.getPathInfo(),但您最好只是尝试理解我指向的源代码(service(..)方法是在调用时调用的方法)你访问servlet)。

#1


2  

Are you using Apache?

你在使用Apache吗?

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

如果是这样,欢迎来到Apache的mod_rewrite令人惊叹的世界。 (http://httpd.apache.org/docs/current/mod/mod_rewrite.html)

Here's the basic concept: you define rules that "rewrite" a URL like oc.tc/itunes89 into oc.tc/show_user.php?username=itunes89 (or whatever you want).

这是基本概念:您可以定义将oc.tc/itunes89等URL“重写”为oc.tc/show_user.php?username=itunes89(或任何您想要的)的规则。

This is an excellent guide to mod_rewrite: http://www.sitepoint.com/guide-url-rewriting-2/. Let me know if you have a specific question or problem implementing it.

这是mod_rewrite的优秀指南:http://www.sitepoint.com/guide-url-rewriting-2/。如果您有实施它的具体问题或问题,请告诉我。

#2


1  

For Apache Tomcat, you can do such things if you map a servlet to a certain URL pattern, and then show the correct page. A tutorial that shows an example can be found here. Together with the source code of the JSPServlet ( here ), you can put together your own servlet that does what you want. I think the method used to retrieve the path is HttpRequest.getServletPath() and HttpRequest.getPathInfo(), but you best just try to understand the source code i pointed to (the service(..) method is the one that is called when you access the servlet).

对于Apache Tomcat,如果将servlet映射到某个URL模式,然后显示正确的页面,则可以执行此类操作。可以在此处找到显示示例的教程。与JSPServlet的源代码(此处)一起,您可以将自己的servlet放在一起,完成您想要的操作。我认为用于检索路径的方法是HttpRequest.getServletPath()和HttpRequest.getPathInfo(),但您最好只是尝试理解我指向的源代码(service(..)方法是在调用时调用的方法)你访问servlet)。