Unofficial Content
  • This documentation is valid for:

The following example shows the use of the Rewrite rule to make your Web page's URL a friendlier one. 

Here, it is specifically shown what needs to be done to take out the '.aspx' from a Web Panel's URL.

Just follow these 3 steps:

(1) Open the file web.config of your KB model.

(2) Insert the following code:

<system.webServer>
    <rewrite>
        <rules>
        <clear />
            <rule name="staticos" patternSyntax="Wildcard" stopProcessing="true">
                <match url="*.js" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                <action type="None" />
            </rule>
            <rule name="aspx resources" stopProcessing="true">
                <match url="(.+)\.aspx$" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
            </rule>
            <rule name="~ home ~" stopProcessing="true">
                <match url=".*execute.xml" />
                <action type="None" />
            </rule>
            <rule name="Pages" stopProcessing="true">
                <match url="^([^/]+)$" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                <action type="Rewrite" url="{R:1}.aspx" appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

(3) Save it and that´s it!

Note: the same can also be done directly from the IIS Manager as explained in this link: Creating Rewrite Rules for the URL Rewrite Module.

As the code shows, 4 rules are added. With those rules (and the procedure FriendlyLink), the '.aspx' at the end of the URL of Web Panel is removed.

The 3rd rule indicates that if the URL matches with ".*execute.xml",  no action is executed. The first rule does the same, but with the pages that ends in '.js'. If those rules are taken out, when you write a URL that matches the pattern, the browser will add '.aspx' at its end, because of the 2nd and 4th rule. These rules do that because the '.aspx' is removed with the procedure FriendlyLink (see FriendlyUrl at Basic Samples - Datatype), but we actually want to see a page that ends in '.aspx'.

Just by picking the appropiate Regular Expressions up, you will be able rewrite the URL as you wish.


 

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant