Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ritesh 1 post 71 karma points
    Aug 28, 2015 @ 08:33
    Ritesh
    0

    Redirect rule

    Hi,

    I want to redirect this url /free-reports?reportid=1259 on this url /free-reports/no-more-metal

    please help me

  • Mark Bowser 261 posts 846 karma points c-trib
    Aug 28, 2015 @ 17:13
    Mark Bowser
    0

    So if someone requests /free-reports/no-more-metal, you want to show them the page at /free-reports?reportid=1259? Is it important for you that the url visibly change? Or do you just want the request to be rewritten?

    If you only care that the query string be passed on but don't need it to be visibly rewritten, you could use the /config/UrlRewriting.config file. An entry like this should do the trick:

        <add name="freeReportsQueryString" 
            virtualUrl="^~/free-reports/no-more-metal?$" 
            rewriteUrlParameter="ExcludeFromClientQueryString" 
            destinationUrl="~/free-reports?reportId=1259" 
            ignoreCase="true" />
    

    If you want the url to be visibly rewritten, I really like to use the IIS Url Rewriting Module for that sort of thing. In the web.config add this:

    <rewrite>
      <rewriteMaps configSource="config/RewriteMaps.config" />
      <rules configSource="config/RewriteRules.config" />
    </rewrite>
    

    And then add those two config files to the /config folder. The RewriteRules.config is for more complex and systematic rewrite rules. In theRewriteRules.config`, just add the following:

    <rules></rules>
    

    In the RewriteMaps.config, add:

    <rewriteMaps>
      <rewriteMap name="StaticRedirects">
        <add key="/free-reports/no-more-metal" value="/free-reports?reportid=1259" />
      </rewriteMap>
    </rewriteMaps>
    

    I'd like to point out that if you go with the above IIS Url Rewriting Module, but forget to install that module on the server running your site, you will get a really, really vague error. Just remember to install the module on every server your site will run on. This probably means installing it on your local machine as well (if it isn't already installed).

    Let me know if this helps at all.

Please Sign in or register to post replies

Write your reply to:

Draft