DEV Community

Sardar Mudassar Ali Khan
Sardar Mudassar Ali Khan

Posted on

URL rewrite in from Aspx to html in asp.net webforms

In ASP.NET WebForms, you can achieve URL rewriting from ASPX to HTML by using the URL rewriting techniques provided by the ASP.NET framework. Here's a step-by-step guide on how to accomplish this:

Step 1: Install the URL Rewrite Module
Before you can start URL rewriting, make sure you have the URL Rewrite Module installed on your web server. If it's not installed, you can download and install it from the Microsoft IIS website.

Step 2: Add a rule to the web.config file
Open the web.config file of your ASP.NET WebForms application and add the following configuration within the <system.webServer> section:

<rewrite>
  <rules>
    <rule name="Rewrite ASPX to HTML">
      <match url="^(.*)\.html$" />
      <action type="Rewrite" url="{R:1}.aspx" />
    </rule>
  </rules>
</rewrite>
Enter fullscreen mode Exit fullscreen mode

This rule specifies that any URL ending with ".html" will be rewritten to the corresponding ".aspx" page.

Step 3: Modify links in your ASPX pages
Since you're rewriting the URLs from ".aspx" to ".html," you need to update the links in your ASPX pages accordingly. Change the file extension in the links to ".html" instead of ".aspx."

For example, if you had a link like this:

<a href="mypage.aspx">My Page</a>
Enter fullscreen mode Exit fullscreen mode

Change it to:

<a href="mypage.html">My Page</a>
Enter fullscreen mode Exit fullscreen mode

Step 4: Test the URL rewriting
After making the necessary changes, publish your website and test the URL rewriting. When you access a URL ending with ".html," it should internally serve the corresponding ".aspx" page without changing the URL in the browser.

That's it! You have successfully implemented URL rewriting from ASPX to HTML in ASP.NET WebForms using the URL Rewrite Module. Remember to update your links whenever you add or rename pages in your application.

Top comments (0)