views:

34

answers:

1

I have a Deluxe Windows Hosting account with Godaddy, and I'm trying to set up URL rewriting with Web.Config.

I read that GoDaddy has the IIS URL Rewrite plugin installed, but they have no support for it whatsoever (see here: http://help.godaddy.com/article/5443)

I tried a simple rewrite rule in my web.config, but nothing happened:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rewriteMaps>
                <rewriteMap name="StaticRedirects">
                  <add key="test.php" value="/test" />
                </rewriteMap>
            </rewriteMaps>
        </rewrite>
    </system.webServer>
</configuration>

When I visit test.php, it doesn't get rewritten to /test and no error is thrown. Any idea why?

Finally, the main rewriting I want to do is from rewrite.php?id=1 to /1.

What matching rule would I have to use to accomplish this, assuming I can get rewriting to work at all?

Thanks in advance!

A: 

To rewrite http://mydom.com/1 to http://mydom.com/test.php?id=1 -

<rules>
  <rule name="tw">
    <match url="([0-9]+)" />
    <action type="Rewrite" url="test.asp?id={R:1}" appendQueryString="false" />
  </rule>
</rules>

To rewrite http://mydom.com/test.php?id=1 to http://mydom.com/1:

<rules>
  <rule name="RedirectUserFriendlyURL1" stopProcessing="true">
    <match url="^test\.php$" />
    <conditions>
      <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
      <add input="{QUERY_STRING}" pattern="^id=([^=&amp;]+)$" />
    </conditions>
    <action type="Redirect" url="{C:1}" appendQueryString="false" />
  </rule>
  <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
    <match url="^([^/]+)/?$" />
    <conditions>
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="test.php?id={R:1}" />
  </rule>
</rules>

I generated these using the UrlRewriter wizard. If you have IIS7 available you can download and install from:

URL Rewrite (IIS.NET)

Kev
Works great, thanks!
MarathonStudios