1

(Hi! This is my first time asking a question on Stack Overflow after years of finding answers here... Thanks!)

I have a dynamic page, and I'd like to have fixed URLs that point to different states of that page. So, for example: "www.mypage.co"(/index.php) is the base page, and it rearranges its content based on user choices. I'd then like to be able to point to "www.mypage.co/contentA" or "www.mypage.co/contentB" in order to automatically load base the page at "www.mypage.co" with the desired content.

At heart the problem is an aesthetic one. I know I could simply write www.mypage.co/index.html?state=contentA to reach the desired end, but I want to keep the URL simple and readable (ie, clean). I also, due to limitations in my hosting relationship, would most appreciate a solution that is server-independent (across LAM[PHP] stacks, at least), if possible.

Also, if I just have incorrect assumptions about how to implement clean URLs, I'd appreciate direction to a good, comprehensive explanation. I can't seem to find one...

4

2 回答 2

0

如果您使用 Apache,则可以使用mod_rewrite。我有一个这样的规则,其中多个静止的 url 都转到同一个页面,使用正则表达式并将旧 url 的部分移动到新 url 的参数中:

RewriteRule ^/testapp/(name|number|rn|sid|unii|inchikey|formula)(/(startswith))?/?(.*) /testapp/ProxyServlet?objectHandle=Search&actionHandle=drillIn&searchtype=$1&searchterm=$4&startswith=$3 [NC,PT]

那个特定的正则表达式接受像这样的网址

  • 测试应用程序/名称
  • testapp/名称/zuchini
  • testapp/name/startswith/zuchini

并将它们转发到同一页面。

我也为 Tomcat 使用UrlRewriteFilter,但正如你提到的 PHP,这似乎没有用。

于 2013-07-26T14:48:14.593 回答
0

您可以使用 htaccess 文件将所有请求重定向到一个位置,然后从那里确定要返回给客户端的内容。查看Tonic使用的htaccess/dispatch 系统。

于 2013-07-26T14:49:34.413 回答