使用 ?lang= 参数重写 URL

发布于 2024-08-25 17:14:28 字数 186 浏览 4 评论 0原文

我的开发人员说不可能重写 url 形式 example.com/name/name/?lang=english 到 example.com/en/name/name/

是否可以这样做? 如果是,应该怎么做? 如果不是,原因可能是什么?

我们有来自 maddogdomains (godaddy) 的基于 Windows 的托管

my developer is saying that it is not possible to rewrite url form
example.com/name/name/?lang=english to
example.com/en/name/name/

is it possible to do or not?
if yes, how should it be done?
if not, what could be the reasons?

we have windows based hosting from maddogdomains (godaddy)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

谁对谁错谁最难过 2024-09-01 17:14:28

您无法“重写”URL,因为用户仍会看到 ?lang 参数。但是,您可以重定向到没有该参数的页面。

他可以检查查询字符串,剥离查询字符串,然后重定向到没有任何查询字符串参数的页面。这应该很容易做到。

但是,请记住,用户被“重定向”到同一页面,因此页面加载速度会较慢,因为它加载了两次。

You can't "rewrite" the URL in a sense that the user will still see the ?lang parameter. However, you can redirect to a page that doesn't have that parameter.

He can check the querystring, strip the querystring, and redirect to the page without any querystring parameters. That should be very easy to do.

However, keep in mind that the user is being "redirected" to the same page, so the page will be slower to load, since it sorta loads twice.

隐诗 2024-09-01 17:14:28

此功能自 .NET 2.0 版本起就已存在。让您的程序员查看 Microsoft 的 ASP.NET 中的 URL 重写。也可以通过 IIS(URL 重写)来完成,但您的托管服务商可能不支持此操作。

您的程序员可能还想查看路由(ASP.NET MVC 路由概述 (C#))。路由由MVC使用,但不限于MVC。它也可以被 ASP.NET 应用程序使用。

This feature has been in .NET since version 2.0. Have your programmer look at URL Rewriting in ASP.NET by Microsoft. It can also be done by IIS (URL Rewrite), but your hoster may not support this.

Your programmer may also want to look at Routing (ASP.NET MVC Routing Overview (C#)). Routing is used by MVC, but is not limited to MVC. It can be used by ASP.NET applications as well.

甜心小果奶 2024-09-01 17:14:28

如果您的主机启用了 mod_rewrite,您当然可以使用它。这是一个教程: http://articles.sitepoint.com/article/guide-url -重写

If mod_rewrite is enabled at your hoster you can use it of course. Here is a tutorial: http://articles.sitepoint.com/article/guide-url-rewriting

許願樹丅啲祈禱 2024-09-01 17:14:28

您的开发人员可能是错的。 Microsoft IIS 的 URL 重写模块可以完全满足您的要求。快速查看主机的软件包无法揭示是否启用了此类模块。也许您应该向他们的支持部门发送电子邮件并询问。如果不可用,更改为不同的网络主机相当容易;有很多好的托管公司。

另一种选择是在应用程序内处理 URL 重定向。具体如何实现这一点取决于所使用的语言和可能的框架以及这些工具如何将 URL 映射到代码。

当开发人员告诉您某些事情不可能时,您通常应该持怀疑态度。几乎总是有办法的。但这并不是说它总是实用的。优秀的开发人员可以解释速度、开发时间和可维护性之间的权衡,并让您做出决定。

Your developer may be wrong. There are URL rewriting modules for Microsoft IIS that can do exactly what you requested. A quick look at your host's packages fails to reveal whether such a module is enabled. Perhaps you should email their support department and ask. If it's not available, changing to a different web host is fairly easy; there are lots of good hosting companies.

Another option is to handle URL redirecting from within your application. Exactly how to accomplish that depends on the language and possibly framework it's written in and how those tools map URLs to code.

You should usually be skeptical when a developer tells you something is not possible. There's almost always a way. That's not to say it's always practical though; a good developer can offer an explanation of the tradeoffs in speed, development time and maintainability and let you make the call.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文