IIS7& 301 重定向 - 文件夹到文件

发布于 2024-08-08 00:15:26 字数 1078 浏览 2 评论 0原文

我们使用 IIS7 和 ASP.NET 3.5。

我们已经用新页面更新了我们的网站。现在,互联网上有许多链接指向我们的网站,但是由于我们新网站的目录结构发生了变化,其中许多链接现在已损坏。

我需要有多个请求,301重定向到“新页面”。许多旧页面只是目录 URL,例如:

/services/softwaredevelopment

/products/geographicdata

/sitemap

/company/termsofuse

我在 Global.asax 文件中编写了一些代码来捕获 url、解析它们并重定向它们。但是,当没有文件引用 (.aspx) 时,我的 ASP.NET 应用程序不会捕获 URL。

看来,这些重定向需要在 IIS7 中创建。

现在,上面的 url 位于目录级别(它们不直接请求实际的 .aspx 页面)...我可以使用虚拟目录将“目录”请求重定向到另一个“目录”...但我无法重定向对实际 .aspx 文件的目录请求

以下是我需要进行的一些重定向类型:

==========

旧:/services/softwaredevelopment

重定向到:/services/custom-software-development。 aspx

============

旧:/sitemap

重定向到:/sitemap.aspx

============

旧:/company/termsofuse

重定向到:/company/termsofuse。 aspx

=============

旧:/company/careers

重定向到:/company/careers.aspx

=============

旧:/services/

重定向到: /services/custom-software-development.aspx

=============

有人可以阐明如何实现这一点吗?如果您有任何疑问,请告诉我。非常感谢您的帮助。

蒂姆

We're using IIS7 and ASP.NET 3.5.

We have updated our website with new pages. Now, there are many links on the internet pointing to our website, however many of those links are now broken due to a change in our directory structure for our new website.

I need to have a number of requests, 301 redirected to the "new page." Many of the old pages are simply directory URL's such as:

/services/softwaredevelopment

/products/geographicdata

/sitemap

/company/termsofuse

I have written some code in the Global.asax file to catch the url's, parse them out, and redirect them. However, when there is no file reference (.aspx), the URL's are not caught by my ASP.NET application.

It seems then, that these redirects need to be created in IIS7.

Now, the urls above are at a directory level (they are not directly requesting an actual .aspx page)... I can redirect a 'directory' request to another 'directory' by using virtual directories.... But I cant redirect a directory request to an actual .aspx file

Here are some of the types of redirects I need to make:

==========

Old: /services/softwaredevelopment

redirect to: /services/custom-software-development.aspx

============

Old: /sitemap

redirect to: /sitemap.aspx

============

Old: /company/termsofuse

redirect to: /company/termsofuse.aspx

=============

Old: /company/careers

redirect to: /company/careers.aspx

=============

Old: /services/

redirect to: /services/custom-software-development.aspx

=============

Can someone shed some light on how to accomplish this? Please let me know if you have any questions. Many thanks for your help.

Tim

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

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

发布评论

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

评论(2

风吹雨成花 2024-08-15 00:15:26

一种快速但肮脏的选择是在您列出的文件夹中创建 default.aspx 重定向页面。例如,要处理 /services/softwaredevelopment,请在 /services/softwaredevelopment/default.aspx 中创建一个文件 default.aspx,其中包含以下内容:

<%@ Page Language="C#" Inherits="System.Web.UI.Page" %>

<% Response.Redirect("/services/custom-software-development.aspx"); %>

此解决方案仅在只有少数重定向的情况下才实用,因为它会使您的项目中的代码文件变得混乱做的很少。对于大量重定向,更好的解决方案是使用 IIS 7 的 原生 URL 重写器

One quick and dirty option is to create default.aspx redirect pages in the folders you have listed. For example, to handle /services/softwaredevelopment, create a file default.aspx at /services/softwaredevelopment/default.aspx with the following:

<%@ Page Language="C#" Inherits="System.Web.UI.Page" %>

<% Response.Redirect("/services/custom-software-development.aspx"); %>

This solution is only practical if there are only a few redirects, as it clutters your project with code files that do very little. A better solution for a large number of redirects is to use IIS 7's native URL rewriter.

孤独陪着我 2024-08-15 00:15:26

查看“Windows Server 2008 上 IIS 7 中的 HTTP 重定向”http://www. trainsignaltraining.com/iis7-redirect-windows-server-2008

您应该能够通过配置 IIS 而不是编码来完成大多数类型的重定向。

Check out "HTTP Redirection in IIS 7 on Windows Server 2008" http://www.trainsignaltraining.com/iis7-redirect-windows-server-2008

You should be able to do most kind of redirect by configuring IIS rather than coding.

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