【问题标题】:Using ISAPI Rewrite 3 & ASP.Net MVC?使用 ISAPI 重写 3 和 ASP.Net MVC?
【发布时间】:2009-11-26 12:20:21
【问题描述】:

我目前在 IIS6 上为两个包含 Wordpress 的虚拟目录使用 ISAPI Rewrite3。

我需要在网站的根目录设置一些规则来将旧网址重定向到新网址:

i.e.

http://www.example.com/somefolder/* > http://www.example.com/newfolder/

&

http://www.example.com/somefolder/file_1.htm > http://www.example.com/newmvcpath/

我需要在不破坏 MVC(因为它设置为通配符)和不影响两个虚拟目录的情况下执行此操作。

另外,我将如何为 /somefolder/file_1.htm 数字位设置通配符。

非常感谢任何帮助

(heliontech iis 重写)

【问题讨论】:

    标签: asp.net-mvc iis-6 isapi-rewrite helicontech


    【解决方案1】:

    .htaccess 文件

    # Helicon ISAPI_Rewrite configuration file
    # Version 3.1.0.64
    
    RewriteEngine on
    
    #301 Redirections
    #FRANCE (all .html files in a folder)
    RewriteRule places-in-france/(.*)\.html places/france [NC,R=301]
    
    #Numeric
    RewriteRule companies-france/Companies-in-Pyrenees_(.*)\.htm companies/france [NC,R=301]
    
    #rest of stuff
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # Add extensions to this rule to avoid them being processed by ASP.NET
    RewriteRule (.*)\.(css|gif|png|jpeg|jpg|js|zip) $1.$2 [I,L]
    
    # Prefixes URLs with "rewritten.aspx/", so that ASP.NET handles them
    RewriteRule ^(.*) /rewritten.aspx/$1 [I]
    

    向 Global.asax.cs 添加代码

    protected void Application_BeginRequest(Object sender, EventArgs e)
    {
        HttpApplication app = sender as HttpApplication;
        if (app != null)
            if (app.Request.AppRelativeCurrentExecutionFilePath == "~/rewritten.aspx")
                app.Context.RewritePath(
                    app.Request.Url.PathAndQuery.Replace("/rewritten.aspx", "")
                );
    }
    

    使用此博客 http://blog.codeville.net/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/ 中的选项 4,但稍作修改。

    这也意味着我已关闭通配符映射。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-22
      • 2011-07-10
      • 2010-10-05
      • 2011-04-01
      • 1970-01-01
      • 2011-03-03
      • 2011-06-24
      • 2010-10-14
      相关资源
      最近更新 更多