简体   繁体   中英

Rewrite rules for localization

I need to translate a web site, and use friendly urls too!, but I can't do the rewrite rules, for my problem. I need something like this.

I've   => http://test.com/test
I need => http://test.com/en-US/test 

Knowing that, I have another rules too, for combine with the new form like this.

<rule name="products">
   <match url="^products/([0-9]+)/([a-zA-Z0-9_-]+)/?$" ignoreCase="true"/>
   <action type="Rewrite" url="/products/Detail.aspx?t={R:1}&amp;i={R:2}" appendQueryString="false"/>
 </rule>

Isn't a good practice copy the rules and put in each sentence, but how to do it?

I'm glad if someone try to help me. My regards!

public class LocaleParser : IHttpModule
{
   public void Init(HttpApplication context)
   {
      context.BeginRequest += context_BeginRequest;
   }

   void context_BeginRequest(object sender, EventArgs e)
   {
       var req = HttpContext.Current.Request.Url.AbsoluteUri;
       var targetUrl = req;

        if (req.IndexOf('/') != -1)
        {
            var langparm = req.Split('/')[1].ToLower();

            switch (langparm)
            {
                case "pt":
                    HttpContext.Current.Items["locale"] = "PT";
                    targetUrl = req.Substring(3);
                    break;
                case "en":
                    HttpContext.Current.Items["locale"] = "EN";
                    targetUrl = req.Substring(3);
                    break;
                case "es":
                    HttpContext.Current.Items["locale"] = "ES";
                    targetUrl = req.Substring(3);
                    break;
            }
        }
    }
}

I solved using this HTTP Module, :D. This guy help me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM