如何将传入流量重定向到另一个站点而不是404页面

时间:2022-11-29 23:07:01

im trying to configure our IIS server to redirect users to another site instead of a 404 page.

我试图配置我们的IIS服务器将用户重定向到另一个站点而不是404页面。

First of all, maybe the title of the question is not correct but i have no idea how to ask for it.

首先,也许这个问题的标题不正确但我不知道如何要求它。

Here's the deal:

这是交易:

  1. we have lots of documents in our IIS server, these documents are reports for our users, might be .pdf, .doc, .xls files etc.
  2. 我们的IIS服务器中有很多文档,这些文档是我们用户的报告,可能是.pdf,.doc,.xls文件等。

  3. currently all of our files are stored in a 2TB HDD but it's getting full and we are considering attaching another HDD that will store all of our current files ( let's call this HDD history )
  4. 目前我们所有的文件都存储在一个2TB硬盘中,但它已经满了,我们正在考虑连接另一个硬盘,它将存储我们当前的所有文件(让我们称之为硬盘历史记录)

  5. we have many applications and emails sent that are using the url to download the file hard-coded ( eg. www.somesite.com/documents/file.pdf ) and we need to deliver the files even if a link sent in an email targets the "old" url, but with the new HDD we will create a virtual directory that will be named "historydocuments" so the correct url for the example before will be www.somesite.com/historydocuments/file.pdf
  6. 我们发送了许多使用网址下载硬编码文件的应用程序和电子邮件(例如www.somesite.com/documents/file.pdf),即使在电子邮件目标中发送链接,我们也需要提供文件“旧”的URL,但是使用新的HDD,我们将创建一个名为“historydocuments”的虚拟目录,因此之前的示例的正确URL将是www.somesite.com/historydocuments/file.pdf

  7. I am trying to do the following: create an url rewrite rule that will try and check if the file exists on the "normal" url (documents) if there's no file there, instead of sending a 404 page, will try to jump to the new virtual directory ( historydocuments ) and try to give the user the file.
  8. 我正在尝试执行以下操作:创建一个url重写规则,它将尝试检查文件是否存在于“普通”URL(文档)上,如果那里没有文件,而不是发送404页面,将尝试跳转到新的虚拟目录(historydocuments)并尝试向用户提供该文件。

All of this is being done in IIS 7.5, i don't know if URL Rewrite is the correct tool for the job and i haven't found anything on SO or the interwebs, so i'm reaching for an IIS Guru to teach me the way to achieve this.

所有这一切都在IIS 7.5中完成,我不知道URL Rewrite是否是正确的工作工具,我没有在SO或者互联网上找到任何东西,所以我正在寻找一位IIS Guru来教我实现这一目标的方法。

Here's an image trying to illustrate the issue: 如何将传入流量重定向到另一个站点而不是404页面

这是一张试图说明问题的图片:

Here's the web.config section of the URL Rewrite

这是URL Rewrite的web.config部分

<rule name="CDocuments Rewrite" stopProcessing="true">
    <match url=".?" />
    <!--<match url="/cdocuments/(.*)?" />-->
    <conditions trackAllCaptures="true">
        <add input="{HTTP_HOST}" pattern="/cdocuments/(.*)?" />
        <add input="{QUERY_STRING}" pattern="/cdocuments/(.*)?" />
    </conditions>
    <action type="Rewrite" url="http://192.168.172.226/filecheck/default.aspx?file={C:2}" appendQueryString="true" logRewrittenUrl="true" />
</rule>

Thanks a lot guys.

非常感谢你们。

1 个解决方案

#1


I don't think IIS URLRewrite can do this. But you can customize your 404 page on the "documents" directory, where you check if the missing file is actually located in the old directory and redirect user to new url if true. You may see many 404 errors in your log, which is not nice.

我不认为IIS URLRewrite可以做到这一点。但您可以在“documents”目录中自定义404页面,在该目录中检查丢失的文件是否实际位于旧目录中,如果为true,则将用户重定向到新URL。您可能会在日志中看到许多404错误,这并不好。

Why not just create a new directory for new documents on the new HDD and keep the old name for old files. Old links will still work and you just send you links in new url. You can actually create some meaningful directories to manage your documents such as www.yourdomain/docs/2015/docufile.pdf. The next upgrade will be much easier.

为什么不在新硬盘上为新文档创建一个新目录,并保留旧文件的旧名称。旧链接仍然有效,您只需在新网址中发送链接即可。您实际上可以创建一些有意义的目录来管理您的文档,例如www.yourdomain / docs / 2015 / docufile.pdf。下一次升级将更容易。

Or use IIS to rewrite

或使用IIS重写

www.yourdomain.com/documents/fileno.pdf

to

www.yourdomain.com/docs/docfind.asp?fname=fileno.pdf

and program the docfind.asp to locate the fileno.pdf and redirect user to the real document url

并编程docfind.asp以找到fileno.pdf并将用户重定向到真实文档URL

www.yourdomain.com/historydocuments/fileno.pdf 

or

www.youdomain.com/newdocuments/fileno.pdf

asp or perl script will do it quickly and easily.

asp或perl脚本可以快速轻松地完成。

The rule should looks like this:

该规则应如下所示:

            <rule name="cddocuments">
                <match url="cddocuments/(.*)" />
                <action type="Rewrite" url="http://192.168.172.226/filecheck/default.aspx?file={R:1}" />
            </rule>

Make sure you rename your old document directory.

确保重命名旧文档目录。

#1


I don't think IIS URLRewrite can do this. But you can customize your 404 page on the "documents" directory, where you check if the missing file is actually located in the old directory and redirect user to new url if true. You may see many 404 errors in your log, which is not nice.

我不认为IIS URLRewrite可以做到这一点。但您可以在“documents”目录中自定义404页面,在该目录中检查丢失的文件是否实际位于旧目录中,如果为true,则将用户重定向到新URL。您可能会在日志中看到许多404错误,这并不好。

Why not just create a new directory for new documents on the new HDD and keep the old name for old files. Old links will still work and you just send you links in new url. You can actually create some meaningful directories to manage your documents such as www.yourdomain/docs/2015/docufile.pdf. The next upgrade will be much easier.

为什么不在新硬盘上为新文档创建一个新目录,并保留旧文件的旧名称。旧链接仍然有效,您只需在新网址中发送链接即可。您实际上可以创建一些有意义的目录来管理您的文档,例如www.yourdomain / docs / 2015 / docufile.pdf。下一次升级将更容易。

Or use IIS to rewrite

或使用IIS重写

www.yourdomain.com/documents/fileno.pdf

to

www.yourdomain.com/docs/docfind.asp?fname=fileno.pdf

and program the docfind.asp to locate the fileno.pdf and redirect user to the real document url

并编程docfind.asp以找到fileno.pdf并将用户重定向到真实文档URL

www.yourdomain.com/historydocuments/fileno.pdf 

or

www.youdomain.com/newdocuments/fileno.pdf

asp or perl script will do it quickly and easily.

asp或perl脚本可以快速轻松地完成。

The rule should looks like this:

该规则应如下所示:

            <rule name="cddocuments">
                <match url="cddocuments/(.*)" />
                <action type="Rewrite" url="http://192.168.172.226/filecheck/default.aspx?file={R:1}" />
            </rule>

Make sure you rename your old document directory.

确保重命名旧文档目录。