locked
Redirect old pages to new pages in web.config RRS feed

  • Question

  • User-417370005 posted

    Hi,

    I'm trying to redirect old pages to new pages in a web.config file. This is the code I'm using now:

            <rewrite>
                <rewriteMaps>
                    <rewriteMap name="StaticRewrites" defaultValue="">
                        <add key="/privacy-policy/soundware-privacy-policy" value="/privacy-policy.html" />
                        <add key="/privacy-policy/bcm-request-privacy-policy" value="/sw-bcm-request.html" />
                        <add key="/privacy-policy/bcm-remote-privacy-policy" value="/sw-bcm-remote.html" />
                        <add key="/privacy-policy/edge-request-privacy-policy" value="/vs-bcm-request.html" />
                        <add key="/privacy-policy/edge-remote-privacy-policy" value="/vs-bcm-remote.html" />
                        <add key="/privacy-policy/orange-door-request-privacy-policy" value="/od-bcm-request.html" />
                        <add key="/privacy-policy/orange-door-remote-privacy-policy" value="/od-bcm-remote.html" />
                        <add key="/privacy-policy/8-orange-door-remote-privacy-policy" value="/od-bcm-remote.html" />
                        <add key="/component/content/" value="/index.html" />
                        <add key="/privacy-policy" value="/privacy-policy.html" />
                        <add key="/contact" value="/contact.html" />
                        <add key="/sitemap" value="/index.html" />
                        <add key="/2-ongecategoriseerd" value="/index.html" />
                        <add key="/" value="/index.html" />
                    </rewriteMap>
                </rewriteMaps>
                <rules>
                    <rule name="Rewrite Rule">
                        <match url=".*" />
                        <conditions>
                            <add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
                        </conditions>
                        <action type="Rewrite" url="{C:1}"/>
                    </rule>
                </rules>
            </rewrite> 

    The problem is that pages with a sub-categorie (e.g. /privacy-policy/....) redirect to the right page but don't show the CSS sheets. So they show just text on a white background.

    The pages without a sub-categorie redirect to the right page but the URL doesn't change. For example: the URL "www.soundware.nl/contact" should redirect to "www.soundware.nl/contact.html" but after redirect it still shows the URL "http://www.soundware.nl/contact"

    I've tryed a lot off things but I can't get it to work properly. Has anybody any suggestions?

    Best regards,

    Frotsmans

    Friday, October 4, 2019 12:26 PM

Answers

  • User-719153870 posted

    Hi Frotsmans,

    So sorry that solution won't work, but i have found another definitely workable solution at .htaccess rewrite URL leads to missing CSS.

    You will need to add below line of code to all of your xxx.html(e.g. /privacy-policy.html) <head> section:

    <base href="http://example.com/">

    In your case, it should be like:

    <base href="http://www.soundware.nl/"> 

    please refer to below code for more information.

    I built a demo with bootstrap.css in the html pages to test if we can get the css file after we redirect the original page:

    /privacy-policy/soundware-privacy-policy.aspx:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <link href="../Content/bootstrap.min.css" rel="stylesheet" />
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <h1>This is the soundware-privacy-policy.aspx</h1>
                <button type="button" class="btn btn-primary">Primary</button>
            </div>
        </form>
    </body>
    </html>

    /privacy-policy.html:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <base href="http://localhost:50606/" />
        <link href="Content/bootstrap.min.css" rel="stylesheet" />
    </head>
    <body>
        <h1>This is the privacy-policy.html</h1>
        <button type="button" class="btn btn-success">Success</button>
    </body>
    </html>

    Here's the result:

    Hope this could work for you too.

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 10, 2019 1:32 AM

All replies

  • User753101303 posted

    Hi,

    Check how you fetch the css sheet. You perhaps use .. to get to the parent directly which won't work at the root.

    For this kind of issue just use F12 Network in your browser to see all http requests done by your browser to the server and you should see it can't fetch CSS files (and you'll see from which location it tries to get them).

    Friday, October 4, 2019 1:08 PM
  • User-417370005 posted

    Hello Patrice,

    I see that it tries to get the CSS sheets (and also the .js) from this location: http://www.soundware.nl/privacy-policy/assets/............

    It should be from: http://www.soundware.nl/assets/..........

    But I don't know why the /privacy-policy/ is in the URL??

    My guess is that it has something to do with the redirect code, but I don't know how to solve this.

    Friday, October 4, 2019 1:21 PM
  • User-719153870 posted

    Hi Frotsmans,

    But I don't know why the /privacy-policy/ is in the URL??

    I think this is because the request to your css file matched the url rewrite rule too.

    Please add below code in your rule:

    <rewrite>
          <rewriteMaps>
            <rewriteMap name="StaticRewrites" defaultValue="">
              <add key="/privacy-policy/soundware-privacy-policy" value="/privacy-policy.html"/>
              <add key="/privacy-policy/bcm-request-privacy-policy" value="/sw-bcm-request.html"/>
              <add key="/privacy-policy/bcm-remote-privacy-policy" value="/sw-bcm-remote.html"/>
              <add key="/privacy-policy/edge-request-privacy-policy" value="/vs-bcm-request.html"/>
              <add key="/privacy-policy/edge-remote-privacy-policy" value="/vs-bcm-remote.html"/>
              <add key="/privacy-policy/orange-door-request-privacy-policy" value="/od-bcm-request.html"/>
              <add key="/privacy-policy/orange-door-remote-privacy-policy" value="/od-bcm-remote.html"/>
              <add key="/privacy-policy/8-orange-door-remote-privacy-policy" value="/od-bcm-remote.html"/>
              <add key="/component/content/" value="/index.html"/>
              <add key="/privacy-policy" value="/privacy-policy.html"/>
              <add key="/Contact" value="/contact.html"/>
              <add key="/sitemap" value="/index.html"/>
              <add key="/2-ongecategoriseerd" value="/index.html"/>
              <add key="/" value="/index.html"/>
            </rewriteMap>
          </rewriteMaps>
          <rules>
            <rule name="Rewrite Rule">
              <match url=".*"/>
              <conditions>
                <add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)"/>
                <add input="{URL}" pattern="^.*\.(ashx|axd|css|gif|png|jpg|jpeg|js|flv|f4v)$" />
              </conditions>
              <action type="Rewrite" url="{C:1}"/>
            </rule>
          </rules>
        </rewrite>

    Hope it could help.

    Best Regard,

    Yang Shen

    Wednesday, October 9, 2019 8:01 AM
  • User-417370005 posted

    Hello Yang Shen,

    Thanks for your help!

    I've added the code to the rules but then I get a 404 error from the pages starting with /privacy-policy/....

    Do you have any other suggestions?

    Wednesday, October 9, 2019 8:14 AM
  • User-719153870 posted

    Hi Frotsmans,

    So sorry that solution won't work, but i have found another definitely workable solution at .htaccess rewrite URL leads to missing CSS.

    You will need to add below line of code to all of your xxx.html(e.g. /privacy-policy.html) <head> section:

    <base href="http://example.com/">

    In your case, it should be like:

    <base href="http://www.soundware.nl/"> 

    please refer to below code for more information.

    I built a demo with bootstrap.css in the html pages to test if we can get the css file after we redirect the original page:

    /privacy-policy/soundware-privacy-policy.aspx:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <link href="../Content/bootstrap.min.css" rel="stylesheet" />
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <h1>This is the soundware-privacy-policy.aspx</h1>
                <button type="button" class="btn btn-primary">Primary</button>
            </div>
        </form>
    </body>
    </html>

    /privacy-policy.html:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <base href="http://localhost:50606/" />
        <link href="Content/bootstrap.min.css" rel="stylesheet" />
    </head>
    <body>
        <h1>This is the privacy-policy.html</h1>
        <button type="button" class="btn btn-success">Success</button>
    </body>
    </html>

    Here's the result:

    Hope this could work for you too.

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 10, 2019 1:32 AM
  • User-417370005 posted

    Hello Yang Shen,

    This solution works like a charm :-)

    Thanks for your great help on this issue!

    Best regards,

    Frotsmans

    Thursday, October 10, 2019 6:36 AM