Copied to clipboard

Flag this post as spam?

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


  • John Churchley 272 posts 1258 karma points c-trib
    May 10, 2016 @ 11:00
    John Churchley
    0

    Currently the site due to culture settings has 2 different url for each page as seen by google.

    domain.com and domain.com/en

    I want to get rid of the /en virtual path by removing it from the culture settings however does anyone have an idea on how I can handle the redirects. It's impracticable to do them individually as the site has over 3000+ pages.

    I.e. domain.com/en/blog needs to redirect to domain.com/blog

  • Casper 69 posts 306 karma points
    May 10, 2016 @ 13:46
    Casper
    1

    In /Config/UrlRewriting.config you can add:

    <add name="enRewrite"
        virtualUrl="~/en/?(.*)"
        rewriteUrlParameter="ExcludeFromClientQueryString"
        destinationUrl="~/$1"
        redirectMode="Permanent"
        redirect="Application"
        ignoreCase="true" />
    

    If you are using IIS7+ you can use Url Rewrite Module - http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

    In web.config you can add:

    <system.webServer>
        <rewrite> 
          <rules>
            <rule name="enRewrite">
              <match url="/en/?(.+)" />
              <action type="Redirect" url="{R:1}" appendQueryString="false" />
            </rule>                 
          </rules>
        </rewrite>
    </system.webServer>
    
  • John Churchley 272 posts 1258 karma points c-trib
    May 11, 2016 @ 08:56
    John Churchley
    0

    UrlRewriting.config addition worked but the rule for the web.config didn't work as expected. Any further advice would be appreciated as the rewrite will be needed long term and UrlRewriting.config is becoming deprecated in Umbraco 8.

    The URL Rewriting rule also create errors when ever a "en" appears in a link. Removing the tilde allowed it to work.

    <add name="enRewrite"
        virtualUrl="/en/(.*)"
        rewriteUrlParameter="ExcludeFromClientQueryString"
        destinationUrl="~/$1"
        redirectMode="Permanent"
        redirect="Application"
        ignoreCase="true" />
    
  • Casper 69 posts 306 karma points
    May 11, 2016 @ 09:55
    Casper
    1

    If you dont want to go with UrlRewriting.config then I have testet this one with success:

    <rewrite> 
      <rules>
        <rule name="enRewrite" stopProcessing="true">
          <match url="^en(.+)?" />
          <action type="Redirect" url="{R:1}" appendQueryString="false" />
        </rule>                 
      </rules>
    </rewrite>
    

    If it does not work, then try to enable failed request tracing and see if you can see the error: http://www.iis.net/learn/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules

  • Casper 69 posts 306 karma points
    May 11, 2016 @ 10:01
    Casper
    0

    BTW - if you are not running IIS express then you can use the IIS Manager -> Url Rewrite tool to test your rules.

Please Sign in or register to post replies

Write your reply to:

Draft