重写到文件服务器

本文关键字:文件服务器 重写 | 更新日期: 2023-09-27 18:37:25

需要将所有文件站点(图片、文档等)放在单独的文件服务器(此处为 dav 服务器或 Amazon c3)上,但 html 中的 url 没有更改,例如:www.site.com/pictures/1.jpg in html 查看 www.davserver/sitename/pictures/1.jpg/我尝试将HttpModule与RewritePath一起使用,但得到错误,虚拟路径错误。

 if (strCurrentUrl.Contains("/files/"))
   {
    app.Context.RewritePath(davserver +strCurrentUrl);
    }

我可以用iss+c#来做,或者只是ngix+rewrite吗?

重写到文件服务器

RewritePath 用于将 URL 重写到服务器内部,您要做的是重定向而不是重写,我更喜欢你做这样的事情:

string fullOrigionalpath = HttpContext.Current.Request.Url.ToString();  
if (fullOrigionalpath.Contains("file"))
{                    
    HttpContext.Current.Response.Redirect("http://stackoverflow.com");
}