Can't get URL Rewrite to work

Discussion in 'DNS/Domain names' started by Robert, Jan 25, 2010.

  1. I still can't figure this out.

    I have www.example.com as my main website. I want the main website to reside in a subfolder called example.

    so, by default, to get to my site, I have to type http://www.example.com/example

    I want anyone who types in www.example.com to get redirected to www.example.com/example (Action Type: redirect).

    And, I want www.example.com/example to show up in the address bar as www.example.com (Action Type: rewrite).

    I just can't seem to get this figured out, any help would be appreciated.


    -- This is what I have so far --
    My Pattern: example\.com
    Redirect URL: {R:0}/example

    I also have the "append query string" box unchecked.
     
  2. Ray

    Ray

    Try setting the redirect URL to R:1 instead of R:0
     
  3. that won't work, there is no way to get a second backreference.
    Can you even do what I am asking, I've searched around and can't find anybody who has done this. And, surely I'm not the only one.

    This isn't a huge deal, just a matter of preference.
     
  4. in your pattern, just put example.com instead of example\.com

    then the redirect url should be example\{R:0}
     
  5. Ray

    Ray

    First you need to setup the condition rule. Inside the conditions make sure you choose {HTTP_POST} and type the patter ^www.example\.com$

    Then choose Rewrite URL rule and type in the text box \example\{R:1}

    This will look for any http calls to www.example.com and redirect it to the folder \example but it will keep the URL to show www.example.com
     
  6. Thanks for your reply guys.

    The rewrite still didn't work. This is what I have.

    Pattern: example.com
    Rewrite URL: \example\{R:0} (I tried {R:1} and it didn't work either)
    - append query string is checked


    {HTTP_POST} Matches the pattern ^www.example\.com$
    - match any

    the webpage loads as normal here.
     
  7. Ray

    Ray

    Lets try to make things simple for now. Make the pattern ^example\.com$ and call your site using example.com as a test. I suspect the issue lies in the pattern that IIS is looking for.
     
  8. Try {HTTP_HOST} instead of {HTTP_POST}.

    Also, it should be {R:1} instead of {R:0}.

    Example:
    Code:
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="demo" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="^demo\.example\.com$" />
                        </conditions>
                        <action type="Rewrite" url="/demo/{R:1}" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    
     

Share This Page