如何配置可选或“无关”的URL?

时间:2022-10-07 21:54:23

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

您将如何配置/处理无关/可选的URL实体(可能是别名)?

SO is a good example:

SO就是一个很好的例子:

  • *.com/questions/99999999/
  • *.com/questions/99999999/question-goes-here (bad example, but I couldn't think of better)
  • *.com/questions/99999999/question-goes-here(糟糕的例子,但我想不出更好)

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

亚马逊网址更加令人困惑(例如,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.

[编辑]这可能不是最好的行动计划,但我真的要问这个与任何一台服务器有关。

5 个解决方案

#1


2  

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.

这种技术通常称为url重写。如果您正在寻找IIS中的解决方案,您可以使用ISAPI重写,这与apache的mod_rewrite非常相似。否则,你可以去ASP.Net MVC路由机制。

#2


2  

If you use Apache, take a look at mod_rewrite

如果您使用Apache,请查看mod_rewrite

#3


1  

Something like this (if manually configuring URLs):

这样的事情(如果手动配置URL):

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.

否则,我让MVC框架处理它并适当地控制控制器的参数。

#4


0  

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

经常使用mod_rewrite,至少在Linux下使用Apache。

#5


-1  

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

这是您的Web应用程序的任务,而不是您的Web服务器。

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.

在URL =>文件映射,如PHP(或静态Web服务器),它是棘手的;但是在MVC框架上它很自然,即使在PHP MVC框架上也是如此。

#1


2  

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.

这种技术通常称为url重写。如果您正在寻找IIS中的解决方案,您可以使用ISAPI重写,这与apache的mod_rewrite非常相似。否则,你可以去ASP.Net MVC路由机制。

#2


2  

If you use Apache, take a look at mod_rewrite

如果您使用Apache,请查看mod_rewrite

#3


1  

Something like this (if manually configuring URLs):

这样的事情(如果手动配置URL):

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.

否则,我让MVC框架处理它并适当地控制控制器的参数。

#4


0  

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

经常使用mod_rewrite,至少在Linux下使用Apache。

#5


-1  

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

这是您的Web应用程序的任务,而不是您的Web服务器。

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.

在URL =>文件映射,如PHP(或静态Web服务器),它是棘手的;但是在MVC框架上它很自然,即使在PHP MVC框架上也是如此。