0

All I want to do is 301 redirect from old URLs to new URLs:

from /xx/yy/somefile.html to /xx/yy/somefile.aspx

some examples below:

add key="/products/DSD-72B-SP-summary.html" value="/products/DSD-72B-SP-summary.aspx" 
add key="/products/DSD-72B-SP-detail" value="/products/DSD-72B-SP-detail.aspx" 
add key="index.html" value="default.aspx" 
add key="/product-selector.html" value="/products.aspx" 

That is all but it doesn't seem to want to work in IIS 7.5 with URL rewrite 2.0.

I have tried at least 10-20 different rules, and rewrite map formats without any luck. In fact I have done this so many times I have had to wipe the rules and maps from IIS and totally recopy a web.config file from a backup to unscrew what I screwed with to try and make it work.

All I need is a simple rule that tells IIS that if it gets a request for a *.html file to display the *.aspx file that replaced the html file.

    <?xml version="1.0" encoding="UTF-8"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <appSettings configProtectionProvider="DataProtectionConfigurationProvider">
    <EncryptedData>
      <CipherData>

      </CipherData>
    </EncryptedData>
  </appSettings>
  <connectionStrings configProtectionProvider="DataProtectionConfigurationProvider">
    <EncryptedData>
      <CipherData>

      </CipherData>
    </EncryptedData>
  </connectionStrings>

  <system.web>

    <customErrors mode="On" defaultRedirect="404-NotFound.aspx">
      <error statusCode="404" redirect="404-NotFound.aspx" />
      <!--<error statusCode="403" redirect=""/>-->
    </customErrors>

    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
            <!--<codeSubDirectories>
                <add directoryName="CSharp"/>
                <add directoryName="VB"/>
            </codeSubDirectories>-->
        </compilation>
    <authentication mode="Forms">

    </authentication>

    <membership>
      <providers>
        <clear />

      </providers>
    </membership>

    <profile>
      <providers>
        <clear />

      </providers>
    </profile>

    <roleManager enabled="false">
      <providers>
        <clear />

      </providers>
    </roleManager>

  </system.web>

  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true">

        </modules>

        <defaultDocument>
            <files>

            </files>
        </defaultDocument>


    <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" path="/404-NotFound.aspx" responseMode="ExecuteURL" />
    </httpErrors>
        <tracing>
            <traceFailedRequests>
                <add path="*">
                    <traceAreas>
                        <add provider="WWW Server" areas="Rewrite" verbosity="Verbose" />
                    </traceAreas>
                    <failureDefinitions statusCodes="200-500" />
                </add>
            </traceFailedRequests>
        </tracing>

  </system.webServer>
</configuration>
d4d4u1
  • 5
  • 2
  • 8

1 Answers1

1

Make sure you clear your cache too. Sometimes you can update a server rule but your browser will continue to show the old page.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
        <rules> 
            <rule name="Vanity URL" enabled="true">
                 <match url=".*" />
                 <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                     <add input="{MAPNAME:{PATH_INFO}}" pattern="(.+)" />
                 </conditions>
                 <action type="Redirect" url="{C:1}" appendQueryString="false" />
            </rule>
        </rules>
        <rewriteMaps>
            <rewriteMap name="MAPNAME">
                <add key="/products/DSD-72B-SP-summary.html" value="/products/DSD-72B-SP-summary.aspx" />
        </rewriteMap>
    </rewrite>
</system.webServer>
</configuration>

The above code it taking directly from my website with minor name changes for generality and added in your page. Try to remove other rules and isolate the issue.

Leeish
  • 5,203
  • 2
  • 17
  • 45
  • Did you copy that exactly. It's not what would be in the entire file. Let me complete it. – Leeish Jan 10 '14 at 22:40
  • ya, that rule and list above just screwed up my entire site with nothing working. – d4d4u1 Jan 10 '14 at 22:42
  • I copied it and put it in my web.config after making temporary rule and list and replacing the rule and list with your above data. So basically I put your rule in place of my rule and your list in place of my list. – d4d4u1 Jan 10 '14 at 22:44
  • Can you post your entire web.config – Leeish Jan 10 '14 at 22:45
  • I'm not super familiar but upload it somewhere and then link to i.t – Leeish Jan 10 '14 at 22:52
  • ok, I added my web.config to the above question I asked. the rule info is removed as it again caused a internal 500 server error. – d4d4u1 Jan 10 '14 at 23:00
  • ok, I have added your code to the web.config I have and now get a 404 page not found. I have checked with the website designer and the directory where the files are located and they are there. I have no idea what is going on and why something I believe to be so simple is not working. – d4d4u1 Jan 10 '14 at 23:07
  • yes, the /products/data-encryption/DSD-72B-SP-summary.aspx is the correct path and the file does exist in that location. I added the /data-encryption/ to your code. – d4d4u1 Jan 10 '14 at 23:14
  • Well. if the URL is correct, the your rewrite map worked and redirected you to the correct location. As for the 404 I would open a new thread. – Leeish Jan 10 '14 at 23:15
  • ?? what could be causing the 404, and how do I know if the redirect worked? – d4d4u1 Jan 10 '14 at 23:17
  • Look at the URL in your browser. Does the URL say you are at the asp page or the html page. I thought you said it sent you to the aspx page. – Leeish Jan 10 '14 at 23:18
  • yes, the path and file are there, but when I type in a url of /products/xx/dsbla.html I get a 404 error, when I should be redirected to the dsbla.aspx page – d4d4u1 Jan 10 '14 at 23:20
  • A few lines up I asked if the URL of the 404 page was correct and you said yes. I guess you misunderstood what I was asking. So, no it's not redirecting you. You do have the rewrite module installed correct? – Leeish Jan 10 '14 at 23:21
  • this is the error I get "http://www.tccsecure.com/404-NotFound.aspx?aspxerrorpath=/*.aspx" when I enter a url of : http://www.tccsecure.com/products/data-encryption/DSD-72B-SP-summary.html, when I want it to go to :http://www.tccsecure.com/products/data-encryption/DSD-72B-SP-summary.aspx and display that page. I have replaced all the html pages with the aspx pages. – d4d4u1 Jan 10 '14 at 23:22
  • yes, url redirect is installed corect and I have done the repair also just in case. – d4d4u1 Jan 10 '14 at 23:22
  • I just clicked on your HTML link and it took me to the aspx page. Clear your broswer cache. – Leeish Jan 10 '14 at 23:23
  • I did that in the beginning, and I just did it and now it works... I AM AN IDIOT!!!!! Sorry, and Thanks you very much for your help. now I have to add the next 100 pages that I have to redirect. – d4d4u1 Jan 10 '14 at 23:30
  • NP. Sticky note that shi to your screen. Clear Cache. :) – Leeish Jan 10 '14 at 23:31
  • LOL!!! Ya, I have that history clearing blocked in a GPO so it is a process for me to clear it manually off my admin system. – d4d4u1 Jan 10 '14 at 23:33