« Previous Next »

Answered Thread: Rewrite Rule Not Working

Last post 06-09-2009 7:48 PM by ruslany. 18 replies.

 

RSS

Page 1 of 2 (19 items) 1 2 Next >

Sort Posts:

  • 06-01-2009, 11:39 AM

    • ixoye
    • Not Ranked
    • Joined on 05-31-2009, 8:10 AM
    • Posts 12

    Rewrite Rule Not Working

    Hello,

     I have written the following rule but with unexpected results. I want the rule to do the following:

     A user registers with our website and is given the follwing URL to view his profile:

    http://username.mywebsite.com

    when he types in the URL the rule is suppose to rewrite the url and take him to:

    http://www.mywebsite.com/users/username

    Mind you, no subdomains are ever created only a folder under users is created upon registration.

    Here is my rule:

    <rule name="MyURLRewriteRule" stopProcessing="false">
    <
    match url="(.*)" />
    <
    conditions>
    <
    add input="{HTTP_HOST}" pattern="^(?!www)(\w+)\.mywebsite\.com$" />
    </
    conditions>
    <
    action type="Rewrite" url="{C:1}/{R:1}" />
    </
    rule>

    Please help!!

    Thanks in advance.

  • 06-01-2009, 4:49 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 7:38 PM
    • Redmond, WA
    • Posts 707

    Answered Re: Rewrite Rule Not Working

    Is this rule located in the web.config file at the root directory of the web site? If yes, then substitution url should be "users/{C:1}/{R:1}".

    http://ruslany.net
  • 06-01-2009, 4:59 PM In reply to

    • ixoye
    • Not Ranked
    • Joined on 05-31-2009, 8:10 AM
    • Posts 12

    Re: Rewrite Rule Not Working

    Thanks for your quick response. Yes, the rule is in the web.config file at the root directory of the web site. Now I have written the substitution url to "users/{C:1}/{R:1}" as you suggested but I keep getting the IIS7 Welcome screen. Any other suggestions?

     Thanks again.

  • 06-01-2009, 5:59 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 7:38 PM
    • Redmond, WA
    • Posts 707

    Answered Re: Rewrite Rule Not Working

    Do you get that when you request any specific file, e.g http://user1.mywebsite.com/something.html or only when you request a default document, e.g. http://user1.mywebsite.com/ ?
    http://ruslany.net
  • 06-01-2009, 6:12 PM In reply to

    • ixoye
    • Not Ranked
    • Joined on 05-31-2009, 8:10 AM
    • Posts 12

    Answered Re: Rewrite Rule Not Working

    The http://mysite.com/users/user1 request works fine. I only get the IIS7 Welcome Screen when requesting http://user1.mywebsite.com/

    Thanks again!

  • 06-01-2009, 6:33 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 7:38 PM
    • Redmond, WA
    • Posts 707

    Re: Rewrite Rule Not Working

    Looks like the rule is not executed at all - most probably because the value of {HTTP_HOST} does not match the specified pattern. Can you try using Failed Request Tracing to see what is the actual value of the {HTTP_HOST} that URL rewriter gets at runtime?

    http://ruslany.net
  • 06-01-2009, 9:54 PM In reply to

    • ixoye
    • Not Ranked
    • Joined on 05-31-2009, 8:10 AM
    • Posts 12

    Re: Rewrite Rule Not Working

    I have used the failed request tracing found here: http://learn.iis.net/page.aspx/467/using-failed-request-tracing-to-trace-rewrite-rules/ and it worked fine. I just don't know how to create one for the rule mentioned above. Your assistance will be greatly appreciated.

     Thanks again!!!!!

  • 06-02-2009, 7:41 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 7:38 PM
    • Redmond, WA
    • Posts 707

    Re: Rewrite Rule Not Working

    If you have followed the steps in the article then you should already have the correct configuration for the tracing. Make a request to http://user1.mywebsite.com/ and then go to \inetpub\logs\FailedReqLogFiles\W3SVC1. (id of your site may be different). In that folder there will be xml file which are the trace log files. Open any and look for URL_REWRITE.

    http://ruslany.net
  • 06-03-2009, 4:00 AM In reply to

    • ixoye
    • Not Ranked
    • Joined on 05-31-2009, 8:10 AM
    • Posts 12

    Re: Rewrite Rule Not Working

    Hi Ruslany,

    In the folder W3SVC3 I opened one of the files but I did not see any URL_REWRITES for  http://user1.mywebsite.com/. I only see URL_REWRITES for http://mysite.com:80/article/244/anytitle which relates to the "Rewrite to Article.aspx" example.

    It seems that whenever I make a request using this format: http://someuser.mywebsite.com it does not make it to the xml file of the W3SVC3 folder. Only requests that don't include a "subdomain" before "mywebsite.com" make it to the xml files.

    Does each "user" need to have a subdomain created in order for the rewrite rule to work? I don't have any subdomains created for mywebsite.com. Please let me know if that's the case.

    Thanks again for your help!!!!

  • 06-04-2009, 2:27 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 7:38 PM
    • Redmond, WA
    • Posts 707

    Re: Rewrite Rule Not Working

    Do you have a separate web site in IIS for mysite.com or do you use "Default Web Site"? The only thing I can think of is that may be you have a separate IIS web site bound to "mysite.com", so any requests to someuser.mywebsite.com get routed to the "Default Web Site", which does not have any rewrite rules and just serves the welcome page.

    http://ruslany.net
  • 06-04-2009, 2:36 PM In reply to

    • ixoye
    • Not Ranked
    • Joined on 05-31-2009, 8:10 AM
    • Posts 12

    Re: Rewrite Rule Not Working

    Yes, I do have a separate web site in IIS for "mysite.com" and that is where I am using the rule. I don't have any rules for the "Default Web Site". Do I need to set the same rules for the "Default Web Site"? In other words, do both "mysite.com" and "Default Web Site" need to have the rules? Thanks!!!
  • 06-04-2009, 2:43 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 7:38 PM
    • Redmond, WA
    • Posts 707

    Re: Rewrite Rule Not Working

    In this case you will need to add a new site binding "username.mywebsite.com" to the mysite.com site. You will have to do it for every user name.

    http://ruslany.net
  • 06-04-2009, 2:56 PM In reply to

    • ixoye
    • Not Ranked
    • Joined on 05-31-2009, 8:10 AM
    • Posts 12

    Re: Rewrite Rule Not Working

    In your last response I noticed that you have used "mywebsite.com" and a "mysite.com". I know that I have mentioned them both in the past. I only have "mysite.com" Do I still need to create the binding for each user? Do I create the rule in the Default Web site or the "mysite.com"?
  • 06-04-2009, 3:26 PM In reply to

    • ixoye
    • Not Ranked
    • Joined on 05-31-2009, 8:10 AM
    • Posts 12

    Re: Rewrite Rule Not Working

    Thank you Ruslany, I got it to work. You have been very helpful.
  • 06-04-2009, 3:50 PM In reply to

    • ixoye
    • Not Ranked
    • Joined on 05-31-2009, 8:10 AM
    • Posts 12

    Re: Rewrite Rule Not Working

    Thanks, Ruslany for your help. Here is how I got it to work. Instead of using "Rewrite" in the Action Type of the rule, I used "Redirect". Now when I request http://user1.mysite.com  it redirects me to http://www.mysite.com/users/user1 That gave me the results I was looking for.

    Now my question is: If I use redirect, do I still need to do the binding for each user? What if I have thousands of users, can the binding be done programmatically so that i don't have to do each one manually?

     Cheers!

     

     

Page 1 of 2 (19 items) 1 2 Next >