Copied to clipboard

Flag this post as spam?

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


  • Saied 349 posts 674 karma points
    Nov 25, 2015 @ 01:28
    Saied
    0

    redirect non-www urls to www urls

    I get 404 when trying to go to a non-www url:

    Is umbraco setup to handle http://sctflash.com and http://www.sctflash.com – I have IIS being able to handle both but for non-www urls umbraco is showing a 404 page. Try

    http://sctflash.com/products/search for example. For http://sctflash.com and for http://bullydog.com I setup a redirect to the www url but I can’t do that for every single page. Can umbraco handle both.

  • Sebastian Dammark 583 posts 1407 karma points
    Nov 25, 2015 @ 09:31
    Sebastian Dammark
    2

    Umbraco can handle both, if you ask it to do so.

    Just add the domains to the page you want it to show.

    Right click the page and choose "Culture and Hostnames" and add both domains here.

    Or you could in your web.config file add the following under system.webServer

    <rewrite>
          <rules>
            <rule name="Add WWW" stopProcessing="true">
              <match url="^(.*)$" />
              <conditions>
                 <add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)$" />
              </conditions>
              <action type="Redirect" url="http://www.{C:0}{PATH_INFO}" redirectType="Permanent" />
            </rule>
          </rules>
        </rewrite>
    

    This will redirect all non-www to the equivalent www url, and respond with a 301 Permanent Redirect.

  • Saied 349 posts 674 karma points
    Nov 25, 2015 @ 13:19
    Saied
    0

    Hi Sebastian,

    I tried entering http://sctflash.com and http://www.sctflash.com in the hostnames, but it still didn't work. I was going to try your rewrite rule next. Will this only work for POSTS? What about GETS?

  • Saied 349 posts 674 karma points
    Nov 25, 2015 @ 14:55
    Saied
    0

    Adding this rule actually threw a 500 error.

  • Osman Coskun 170 posts 404 karma points
    Nov 03, 2017 @ 05:34
    Osman Coskun
    0

    Thank you Sebastian.

    What if i wanted to redirect a domain alias to main domain, how would i construct the rule? I mean to redirect mysite2.com to www.mymainsite.com.

    Best regards...

  • Michael Nielsen 153 posts 810 karma points
    Nov 25, 2015 @ 13:53
    Michael Nielsen
    0

    Looks as if you fixed it.

    But it can also be done in UrlRewriting.config

    <urlrewritingnet xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
      <rewrites>    
        <add name="seoCanonical" virtualUrl="http://domain.com/(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="http://www.domain.com/$1" redirect="Domain" redirectMode="Permanent" ignoreCase="true" />
        <add name="rewriteFolderSlashes" virtualUrl="^~/((?!umbraco/).[^?]*)/$" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/$1" redirect="Application" ignoreCase="true" redirectMode="Permanent" />
      </rewrites>
    </urlrewritingnet>
    

    First rule is from non-www to www

    Second rule is to redirect from with trailing slash to no trailing slash.

    So that i.e this URL

    http://www.sctflash.com/products/search/

    also would work

  • Saied 349 posts 674 karma points
    Nov 25, 2015 @ 14:57
    Saied
    0

    Hi Michael,

    I actually never fixed it. Adding both hostnames, sctflash.com and www.sctflash.com didn't do anything and the rewrite rule didn't fix it (it threw a 500). I have yet to try your solution yet. How would I be able to redirect sctflash.com to www.sctflash.com and bullydog.com to www.bullydog.com for both the root of the website and nested pages so http://sctflash.com/products/search becomes http://www.sctflash.com/products/search

  • Paul Seal 524 posts 2889 karma points MVP 7x c-trib
    Nov 03, 2017 @ 06:47
    Paul Seal
    0

    Hi Saied

    Have a look at this blog post, it should help you out. http://www.codeshare.co.uk/blog/how-to-create-url-rewrite-rules-in-umbraco/

    Essentially, you need both addresses in the bindings in IIS.

    Then in your urlrewriting config you add a rule to go from the non www address to the www address.

    <?xml version="1.0" encoding="utf-8"?>
      <urlrewritingnet xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
        <rewrites>
        <!-- Use this rule to redirect a url without www at the front to one with www at the front. - From http://codeshare.co.uk to http://www.codeshare.co.uk -->
        <add name="NoWWW" virtualUrl="^http\://codeshare\.co\.uk/(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="http://www.codeshare.co.uk/$1" redirect="Domain" redirectMode="Permanent" ignoreCase="true" />
      </rewrites>
    </urlrewritingnet>
    
  • Marcio Goularte 388 posts 1360 karma points
    Nov 03, 2017 @ 14:41
    Marcio Goularte
    0

    Just to remember that Urlrewriting was removed in version 7.7.x. I also do not recommend it. I had recent problems where it caused 100% CPU.

    I migrated to the IIS Url Rewrite

Please Sign in or register to post replies

Write your reply to:

Draft