locked
301 SEO redirect in web.config RRS feed

  • Question

  • User-492280791 posted

    Hi all,

    I want to add a few 301 seo redirects in my web.config file. I tried to add this part but I always get error messages. What is the correct location to add this? 

    <configuration>
      <location path="http://www.xxx.com/yyy.html">
        <system.webServer>
          <httpRedirect enabled="true" destination="https://www.xxx.com/nl" httpResponseStatus="Permanent" />
        </system.webServer>
      </location>
    </configuration>

    my web.config is structured like this:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <section name="NopConfig" type="Nop.Core.Configuration.NopConfig, Nop.Core" requirePermission="false" />
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        <section name="resizer" type="ImageResizer.ResizerSection,ImageResizer" requirePermission="false" />
      </configSections>
      <appSettings>
        <add key="owin:AutomaticAppStartup" value="false" />
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="PreserveLoginUrl" value="true" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
        <!-- Uncomment one of the settings below if your hosting uses a load balancer. It'll be used to determine whether the current request is HTTPS.-->
        <!--<add key="Use_HTTP_CLUSTER_HTTPS" value="true" />-->
        <!--<add key="Use_HTTP_X_FORWARDED_PROTO" value="true" />-->
        <!-- Uncomment the setting below if your hosting doesn't use "X-FORWARDED-FOR" header to determine IP address.
        In some cases server use other HTTP header. You can specify a custom HTTP header here. For example, CF-Connecting-IP, X-FORWARDED-PROTO, etc-->
        <!--<add key="ForwardedHTTPheader" value="CF-Connecting-IP" /> -->
        <add key="aspnet:MaxJsonDeserializerMembers" value="150000" />
      </appSettings>
      <NopConfig>
        <!-- Web farm support
        Enable "MultipleInstancesEnabled" if you run multiple instances.
        Enable "RunOnAzureWebApps" if you run on Windows Azure Web Apps (not cloud services). -->
        <WebFarms MultipleInstancesEnabled="False" RunOnAzureWebApps="False" />
        <!-- Windows Azure BLOB storage. Specify your connection string, container name, end point for BLOB storage here -->
        <AzureBlobStorage ConnectionString="" ContainerName="" EndPoint="" />
        <!-- Redis support (used by web farms, Azure, etc). Find more about it at https://azure.microsoft.com/en-us/documentation/articles/cache-dotnet-how-to-use-azure-redis-cache/ -->
        <RedisCaching Enabled="false" ConnectionString="localhost" />
        <!-- You can get the latest version of user agent strings at http://browscap.org/ -->
        <!-- Leave "crawlersOnlyDatabasePath" attribute empty if you want to use full version of "browscap.xml" file -->
        <UserAgentStrings databasePath="~/App_Data/browscap.xml" crawlersOnlyDatabasePath="~/App_Data/browscap.crawlersonly.xml" />
        <!-- Set the setting below to "False" if you did not upgrade from one of the previous versions. It can slightly improve performance -->
        <SupportPreviousNopcommerceVersions Enabled="True" />
        <!-- Do not edit this element. For advanced users only -->
        <Installation DisableSampleDataDuringInstallation="False" UseFastInstallationService="False" PluginsIgnoredDuringInstallation="" />
      </NopConfig>
      <system.web>
      <identity impersonate="true" />
        <customErrors defaultRedirect="errorpage.htm" mode="Off">
          <!-- We handle all 404 errors in "PageNotFound" method of "CommonController". But let's have it here anyway. -->
          <error statusCode="404" redirect="filenotfound.htm" />
        </customErrors>
        <trace enabled="false" localOnly="true" />
        <compilation debug="true" targetFramework="4.5.1" numRecompilesBeforeAppRestart="150" />
        <authentication mode="Forms">
          <forms name="NOPCOMMERCE.AUTH" loginUrl="~/login" protection="All" timeout="43200" path="/" requireSSL="false" slidingExpiration="true" />
        </authentication>
        <pages>
          <namespaces>
            <add namespace="System.Web.Helpers" />
            <add namespace="System.Web.Mvc" />
            <add namespace="System.Web.Mvc.Ajax" />
            <add namespace="System.Web.Mvc.Html" />
            <add namespace="System.Web.Optimization" />
            <add namespace="System.Web.Routing" />
            <add namespace="System.Web.WebPages" />
          </namespaces>
        </pages>
        <httpRuntime targetFramework="4.5.1" enableVersionHeader="false" />
        <!--Use <sessionState> commented below in order to support Redis (used by web farms, Azure, etc).
        Find more about it at https://azure.microsoft.com/en-us/documentation/articles/cache-dotnet-how-to-use-azure-redis-cache/#store-session -->
        <!--<sessionState mode="Custom" customProvider="MySessionStateStore">
          <providers>
            <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="localhost" accessKey="" ssl="true" />
          </providers>
        </sessionState>-->
      </system.web>
      <system.webServer>
    
    
    
        <httpProtocol>
          <customHeaders>
            <remove name="X-Powered-By" />
          </customHeaders>
        </httpProtocol>
        <modules runAllManagedModulesForAllRequests="true">
          <remove name="UrlRoutingModule" />
          <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        </modules>
        <staticContent>
          <!--Cache static content for 7 days-->
          <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
          <!--Allow json file loading (used by Roxy Fileman)-->
          <remove fileExtension=".json" />
          <mimeMap fileExtension=".json" mimeType="application/json" />
          <!--Allow database backup (.bak) file loading -->
          <remove fileExtension=".bak" />
          <mimeMap fileExtension=".bak" mimeType="application/octet-stream" />
          <!--Allow and otf, woff, woff2 file loading (used by fontawesome)-->
          <remove fileExtension=".otf" />
          <remove fileExtension=".woff" />
          <remove fileExtension=".woff2" />
          <mimeMap fileExtension=".otf" mimeType="application/x-font-opentype" />
          <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
          <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
        </staticContent>
    <httpCompression directory="%SystemDrive%\inetpub\ temp\IIS Temporary Compressed Files">
        <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
        <dynamicTypes>
          <add mimeType="text/*" enabled="true" />
          <add mimeType="message/*" enabled="true" />
          <add mimeType="application/javascript" enabled="true" />
          <add mimeType="*/*" enabled="false" />
        </dynamicTypes>
        <staticTypes>
          <add mimeType="text/*" enabled="true" />
          <add mimeType="message/*" enabled="true" />
          <add mimeType="application/javascript" enabled="true" />
          <add mimeType="*/*" enabled="false" />
        </staticTypes>
      </httpCompression>
        <urlCompression doStaticCompression="true" doDynamicCompression="true" />
        <validation validateIntegratedModeConfiguration="false" />
        <handlers>
          <add name="SitemapXml" path="sitemap*.xml" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
          <add name="RobotsTxt" path="robots.txt" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
          <add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
          <add name="DenyAccessToPluginDLLs" verb="*" path="*.dll" type="System.Web.HttpForbiddenHandler" />
          <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
          <remove name="OPTIONSVerbHandler" />
          <remove name="TRACEVerbHandler" />
          <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
    
            <httpRedirect enabled="False" destination="https://www.xxx.com" />
    
    	<directoryBrowse enabled="true" />
            <defaultDocument>
                <files>
                    <add value="Global.asax" />
                </files>
            </defaultDocument>
      </system.webServer>
      <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <probing privatePath="Plugins/bin/" />
          <dependentAssembly>
            <assemblyIdentity name="FluentValidation" publicKeyToken="a82054b837897c66" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.4.0.0" newVersion="3.4.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.4.0.0" newVersion="4.4.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Http.WebHost" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="MiniProfiler" publicKeyToken="b44f9351044011a3" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.2.0.157" newVersion="3.2.0.157" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.8.1.0" newVersion="5.8.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.8.1.0" newVersion="5.8.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.8.1.0" newVersion="5.8.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="StackExchange.Redis.StrongName" publicKeyToken="c219ff1ca8c2ce46" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-1.2.1.0" newVersion="1.2.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Azure.KeyVault.Core" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <system.data>
        <DbProviderFactories>
          <remove invariant="System.Data.SqlServerCe.4.0" />
          <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
        </DbProviderFactories>
      </system.data>
      <entityFramework>
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
          <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
        </providers>
      </entityFramework>
      <resizer>
        <plugins>
          <add name="PrettyGifs" />
        </plugins>
      </resizer>
    </configuration>
    Thursday, December 14, 2017 7:04 PM

All replies

  • User2103319870 posted

    I tried to add this part but I always get error messages. What is the correct location to add this? 

    If you are asking about specific node location in web.config, then you can add it below to system.web node. I have the path at this location and its working fine

    <?xml version="1.0" encoding="utf-8"?>
    <!--For more information on how to configure your ASP.NET application, please visit-->
    <!--https://go.microsoft.com/fwlink/?LinkId=169433-->
    <configuration>
      <system.web>
      </system.web>
      <location path="http://www.xxx.com/yyy.html">
        <system.webServer>
          <httpRedirect enabled="true" destination="http://www.xxx.com/yyy.html/nl" httpResponseStatus="Permanent" />
        </system.webServer>
      </location>
    </configuration>

    https://msdn.microsoft.com/en-us/library/ms178692.aspx

    Thursday, December 14, 2017 7:35 PM
  • User-492280791 posted

    @A2H so like this?

    ...
    </system.web>
    <configuration>
      <location path="http://www.xxx.com/yyy.html">
        <system.webServer>
          <httpRedirect enabled="true" destination="https://www.xxx.com/nl" httpResponseStatus="Permanent" />
        </system.webServer>
      </location>
    </configuration>
    <system.webServer>
    ...
    Thursday, December 14, 2017 7:40 PM
  • User2103319870 posted

    no with out the configuration node. Configuration is root node and config file should have only one. Try like below

    </system.web>
    
      <location path="http://www.xxx.com/yyy.html">
        <system.webServer>
          <httpRedirect enabled="true" destination="https://www.xxx.com/nl" httpResponseStatus="Permanent" />
        </system.webServer>
      </location>
    
    <system.webServer>
    Thursday, December 14, 2017 7:53 PM