url rewriting - Asp.net 4 url rewrite a subdomain as a folder -
what i'm trying following, want rewrite kind of url:
blog.domain.com/...
into
domain.com/blog/...
it's in shared host environment, using iis7/asp.net 4. thing both domain , blog subdomain have different aps running. i've been searching hours what's best solution here, , hope can guide me bit here. thanks!
here attempt first idea.
// keep valid list somewhere list<string> cvalidnames = new list<string>(); cvalidnames.add("blog"); // host //string thehost = request.url.host; string thehost = "blog.domain.com"; // find first part, assume domain standard , not change int wherestarts = thehost.indexof(".domain.com"); // if found if(wherestarts != -1) { string cthefirstpart = thehost.substring(0, wherestarts); // if on valid domain (exclude www) if (cvalidnames.contains(cthefirstpart)) { // add in frond name , continue rest url string cfinalpath = "/" + cthefirstpart + request.rawurl; // rewrite it. httpcontext.current.rewritepath(cfinalpath, false); return; } }
Comments
Post a Comment