Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>These are the standard rewrite rules I start every project with. I use only clean URLs for all the pages (example first rule works for www.example.com/about and second rule www.example.com/product/123)</p> <pre><code>&lt;rewrite&gt; &lt;rules&gt; &lt;rule name="Rewrite default to aspx" stopProcessing="true"&gt; &lt;match url="^$" ignoreCase="false" /&gt; &lt;action type="Rewrite" url="default.aspx" /&gt; &lt;/rule&gt; &lt;rule name="Rewrite page to aspx" stopProcessing="true"&gt; &lt;match url="^([a-z0-9/]+)$" ignoreCase="false" /&gt; &lt;action type="Rewrite" url="{R:1}.aspx" /&gt; &lt;/rule&gt; &lt;/rules&gt; &lt;/rewrite&gt; </code></pre> <p>Pages where I need to parse out the ID (this case number only) and add it to the query string I add a similar rule to the front:</p> <pre><code>&lt;rule name="Rewrite Product ID" stopProcessing="true"&gt; &lt;match url="^product/([0-9]+)$" ignoreCase="false"/&gt; &lt;action type="Rewrite" url="product.aspx?id={R:1}"/&gt; &lt;/rule&gt; </code></pre> <p>If you want to use lower and upper case letters in the URL, set ignoreCase="true"</p> <p><strong>Edit to answer your second question plus a bonus</strong></p> <p>This rule will redirect aspx page to the clean URL:</p> <pre><code>&lt;rule name="Redirect to clean URL" stopProcessing="true"&gt; &lt;match url="^([a-z0-9/]+).aspx$" ignoreCase="true"/&gt; &lt;action type="Redirect" url="{R:1}"/&gt; &lt;/rule&gt; </code></pre> <p>Replace url="{R:1}" with url="{ToLower:{R:1}}" to change URL to lowercase. See below why you would want to do this.</p> <p>Also a good idea to update the Form action so that post backs don't return back to the ugly URL. Using IIS 7.5 or newer this should work:</p> <pre><code> if (!String.IsNullOrEmpty(Request.RawUrl)) form1.Action = Request.RawUrl; </code></pre> <p>or for IIS 7:</p> <pre><code> if (!String.IsNullOrEmpty(Context.Request.ServerVariables["HTTP_X_ORIGINAL_URL"])) form1.Action = Context.Request.ServerVariables["HTTP_X_ORIGINAL_URL"]; </code></pre> <p>One more thing to keep in mind... it's a good idea to keep all URLs lower case. Mixing lower/upper case characters in the URL creates duplicate content issues for SEO/Google. For example website.com/About and website.com/about will load the same page, but Google will index them as two separate pages.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload