How do configure optional or “extraneous” URLs?

蓝咒 提交于 2019-12-11 12:29:21

问题


How would you configure/handle extraneous/optional URLs entities (aliases, maybe)?

SO is a good example:

  • stackoverflow.com/questions/99999999/
  • stackoverflow.com/questions/99999999/question-goes-here (bad example, but I couldn't think of better)

Amazon URLs are even more confusing (e.g., the Kindle)

  • amazon.com/gp/product/B000FI73MA/
  • amazon.com/Kindle-Amazons-Wireless-Reading-Device/dp/B000FI73MA/

[EDIT] This probably isn't the best plan-of-action, but I'm really asking this in general vs. for any single server.


回答1:


This technique is commonly known as url rewriting. If you are looking out for a solution in IIS, you can use ISAPI rewrite, which is quite similar to mod_rewrite for apache. Or else, you can go for ASP.Net MVC routing mechanism.




回答2:


If you use Apache, take a look at mod_rewrite




回答3:


Something like this (if manually configuring URLs):

RewriteRule ^([^\/]+)\/([^\/]+)\/(.*) index.php?controller=$1&view=$2&args=$3

Otherwise I let the MVC framework handle it and taylor the controller's arguments as appropriate.




回答4:


mod_rewrite is often used, at least under Linux with Apache.




回答5:


That's a task for your web app, not your web server.

On URL=>file mappings, like PHP (or static webservers) it's tricky; but on MVC frameworks it's quite natural, even on PHP MVC frameworks.



来源:https://stackoverflow.com/questions/180007/how-do-configure-optional-or-extraneous-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!