URL Rewrite

Discussion in 'General troubleshooting' started by n8nt, Oct 12, 2009.

  1. I have a domain pointer called like pointer.com which is pointing at my site which is like www.mysite.com. My application start folder for pointer.com is a folder named pointer. I might have a second pointer called pointer2.com and it would be in a folder named pointer2. My main site, www.mysite.com is at the root of my site.

    So I want to be able to enter either of the following in my browser:


    And I need it to go to


    Actually I have a default.aspx in both pointed folders, so what I really need the browser to do is to go to


    Now I can do this with a simple program in my root that looks like this:
    protected void Page_Load(object sender, EventArgs e)
    EnableViewState = false;
    string site = Request.ServerVariables["HTTP_HOST"];
    Response.Write(string.Format("Site is {0}", site));

    if ((site == "pointer.com") || (site == "www.pointer.com"))
    Response.Write("Using old way to redirect.");

    However, the browser then shows ther url as "http://pointer.com/pointer/default.aspx" instead of
    "http://pointer.com/default.aspx" which is what I'd like to see.

    I've tried using the URL Rewrite through the IIS Manager but it just doesn't seem to work. I figure I'm not setting up the rules correctly. Here are two rules I tried
    <rule name="pointer rule" enabled="true">
    <match url="pointer.com" />
    <action type=
    "Rewrite" url="http://{R:0}/pointer/default.aspx" />
    <rule name="pointer2 rule">
    <match url="pointer2.com" />
    <action type=
    "Rewrite" url="{R:0}/pointer2/default.aspx" />

    Any Ideas anyone?
  2. I figured it out...

    In case anyone is interested I think I figured it out.
    If I add this rule then I can do exactly what I want.

    <rule name="pointer test" stopProcessing="false">
    <match url=".*" />
    <add input="{HTTP_HOST}" pattern="pointer.com" />
    <action type="Rewrite" url="pointer/default.aspx" />

    So, I couldn't get any help on this but maybe someone else can benefit from my research!
  3. Well, this works but not quite as I would have hoped. The pointerDomain site doesn't seem to be able to access any relative paths that are in the script. I guess it is using the re-written URL. More investigation needed now. I'll take help if it is out there!
  4. I suspect that it has to do with the fact that you are Rewriting all requests to pointer/default.aspx.

    Try pointer/{R:1} instead.
  5. url rewrite fixed

    Thanks. That was almost was perfect. I just had to change it to


    instead of

  6. Here's a rewriting rule that can go it web.config in the root, and direct both x.y and www.x.y to a subfolder sitedir.x.y, regardless of what x and y are. It assumes you have no urls that begin with sitedir. The advantage is that you don't have to change web.config every time you add a new site, if you simply follow the sitedir.x.y convention.

    <?xml version="1.0" encoding="UTF-8"?>
    <clear />
    <rule name="^sitedir." stopProcessing="true">
    <match url="^sitedir." />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
    <action type="None" />
    <rule name="Remove www" patternSyntax="ECMAScript" stopProcessing="true">
    <match url="(.*)" negate="false" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{HTTP_HOST}" pattern="(^www\.)(.+)" />
    <action type="Rewrite" url="sitedir.{C:2}/{PATH_INFO}" appendQueryString="true" />
    <rule name="WildCard" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
    <action type="Rewrite" url="sitedir.{HTTP_HOST}/{PATH_INFO}" />
    <directoryBrowse enabled="false" />
  7. Ray


    WOW, actually this is a nice rule. I'm gonna have to test this out. Of course this may hinder some people who have domain pointers and they have those additional domain names point to a different sub folder.
  8. Handling URLs with Hyphens

    Note that the web.config I posted on 5/25/10 does not work on domain names that contain hyphens. I forget why, but I think it's because filenames cannot contain hyphens. Attached is a new version. It's untested in this form, but it probably works.

    Attached Files:

  9. Holy crap - nice!
  10. i love the rule but it breaks ajax applications like every other one, how can i get around this?
  11. I mostly use Silverlight for new development, but I do have one AJAX page that seems to work OK. It uses a Microsoft UpdatePanel and a Telerik RadComboBox.

    Do you know why your AJAX breaks?
  12. Well no not really it never made any sense, i keep getting errors like: ASP.NET Ajax client-side framework failed to load and 'Sys' is undefined.

    What seems to be breaking it is that ScriptResource.axd is not actually being generated and i can't figure out why.

    Have you ever had this problem?

    If not could you please send me an example of a working Microsoft ASP.NET AJAX Application that works with URL Rewriting or something :).
  13. Ray


    This doesn't sound like a URL problem. Really, the best thing to do is send a full and complete copy of the error message and if possible send us a URL and a way to see the error on our end.
    One of the most common problems with diagnosing coding problems is the person seeing the problem concludes to what he/she thinks is the problem and leads everybody to that path, when in essence it is completely something else.
    So its always best to just give the exact error first then let someone else (a new fresh set of eyes) conclude what the problem maybe.
  14. http://www.gabrielsadaka.com.au/ajax/default.aspx

    After heaps of work i mangaged to get it working with internet explorer but for some reason neither firefox nor chrome can render the ajax properly :S

    Just to let you know I'm only 16 so I don't really have a great deal of experience in this :).
  15. Ray


    WOW you guys are getting younger and younger everyday. The fact that you are already dealing with AJAX/.Net/WCF will definitely put you on the path in the world of programming. Keep it up, before you know it a lot of corporations will be knocking at your door to hire you.

    As for firefox and chrome, AJAX relies on or should I say requires client side java scripting. You may want to make sure you got the latest version of java installed on your computer.
  16. Actually for some reason it doesn't work in Internet Explorer either, i think that would be because i got rid of the URL rewrite rule to test it, which made it work, then set it back but i didn't clear the temporary files, so it just loaded up the original one which worked without the URL rewriting.

    So in conclusion it actually doesn't work in any browser like it was in the beginning, any other ideas (installing java won't fix it because JavaScript and Java are entirely unrelated :) )
  17. Ray


    The browser errors you are getting it not very helpful.

    Go to this site and download fiddler and install it on your computer. It is a debugger application and it will log all the http calls your AJAX application will make. This should give you a more better understanding on what is going on in the back end and implement a solution to it.

  18. been there done that :)

    sorry i should've mentiod that fiddler showed that ScriptResource.axd is giving a 404 error, from that i have guessed that for some reason it is either not getting generated at all or it is being generated in a different location, either way isn't very helpful :S
  19. I found the solution to this. I'm at work and I can't use FTP to get the rules. I got ajax working in sub folders. I will post a separate write up because lots of people need it.
  20. pleunv, Scott has been working with me to come up with the rules I have posted in the programming forum. I"m not sure if he updated his blog yet, but I followed his blog 100% correctly and it wasn't working. That's when he got involved and got us a working solution

    He'll be working with me again on some SEO friendly rewrites and I'll be sure to post anything he offers up. It seems even the basic things aren't always so basic.

Share This Page