Products

Solutions

Learn More

Partners

Community

Blog

About

The Community Blog is a personal opinion of community members and by no means the official standpoint of DNN Corp or DNN Platform. This is a place to express personal thoughts about DNNPlatform, the community and its ecosystem. Do you have useful information that you would like to share with the DNN Community in a featured article or blog? If so, please contact .

The use of the Community Blog is covered by our Community Blog Guidelines - please read before commenting or posting.


Redirects in DNN

Redirects are important in many scenarios.  Sometimes even crucial.
You could think of a marketeer that likes to communicatie www.domain.com/sale that is actually www.domain.com/travels-to-europe. This is the kind where you could create a page ‘sale’ in DNN and tell the settings to redirect www.domain.com/travels-to-europe. 

But there are other scenarios where you have to dig into the web.config to accomplish what you want. This wiki is intended to start with some common scenarios, not to be complete at first start. 

Be careful 

Editing your web.config is something you need to do carefully. A mistake can take your website down, so always backup your web.config. I always have a web.config.old standby so I can use Filezilla to revert. 

You can not put it anywhere 

So, your web.config needs to be constructed in a certain way. There is the section of your redirect rules and where you put it in the existing web.config.  
 
Your redirect section itself will look like 

<rewrite> 
<rules> 
Here the actual rules 
</rules> 
</rewrite> 

Now, where to put this bit... 
Look for the section with httpProtocol.  
    <httpProtocol> 
      <customHeaders> 
        <remove name="X-Powered-By" /> 
      </customHeaders> 
    </httpProtocol> 

Your piece of work goes below this, so it will become like: 

    <httpProtocol> 
      <customHeaders> 
        <remove name="X-Powered-By" /> 
      </customHeaders> 
    </httpProtocol>  
       <rewrite> 
         <rules> 
Here the actual rules 
         </rules> 
       </rewrite> 

 Now, the different type of redirects. And all of them use regular expressions, so it helps if you can read them. If not, you can copy the code below and put in your own domain name. 

Force https 
These days, there is really no debating whether SSL is mandatory or not. Certificates are cheap or free and installing them has never been easier. Next stop is to ensure visitors are not getting the non-ssl version of your website. So, we’re going to redirect them to the SSL version. 

Some hosting providers offer Plesk which has the option to force SSL but if you don’t have that option or feel more comfortable to use the web.config, here are 2 examples how you can do this. 

Version 1
<rewrite> 
<rules>   
<rule name="Redirect to https" stopProcessing="true">   
<match url="(.*)" />     
<conditions>     
<add input="{HTTPS}" pattern="off" ignoreCase="true" />     
</conditions>     <action type="Redirect" url="https://{HTTP_HOST}/{R:1}"                    redirectType="Permanent" />   
</rule>
</rules>
</rewrite> 

Version 2
<rule name="Redirect to https " enabled="true" patternSyntax="Wildcard" stopProcessing="true"> 
<match url="*" negate="false" /> 
<conditions logicalGrouping="MatchAll"> 
<add input="{HTTPS}" pattern="off" /> 
<add input="{HTTP_HOST}" pattern="www.mywebsite.com" /> 
</conditions> 
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" /> 
</rule> 

 Second domain 
Some customers have multiple domains that need to be directed to the main site. Most of the time, extra domains are bought for easier communication, claiming a generic word or alternations on the main domain name.  

Of course, you don’t want to maintain multiple sites, not paying extra domain names in your certificates and not paying for modules that are licensed to a domain. So, again, we’re going to redirect. This time, the extra domain (domain 2) simply needs to be directed to domain 1 

As the extra domain has not been indexed by Google, we can suffice with: 

<rule name="redirect to another domain" enabled="true" patternSyntax="Wildcard" stopProcessing="true"> 
<match url="*" negate="false" /> 
<conditions logicalGrouping="MatchAll"> 
<add input="{HTTP_HOST}" pattern="www.domain2.com" /></conditions> 
<action type="Redirect" url="http://www.domain1.com{REQUEST_URI}" redirectType="Permanent" /> 
</rule> 

 Catching old traffic 

Worst nightmare: you win a new client, build a great webshop, far better than the old WooCommerce, smooth project, go live and...sales drop. Big time. 

Good chance that 90% of the traffic is getting a 404 page and leave. The old shop was structured differently or even had pages ending at .php. Besides disappointed customers, Google will punish you as well. Page authority and domain authority are loosing points and are hard to regain. 

Of course, the ideal situation is to redirect the old url of product A to the new url of product A. But this can easily result in thousands of redirects. If you’re not Aliexpress, you might consider this too much work. The alternative is to redirect everything ending on .php. For this scenario a redirect looks like: 

<rule name="Redir old urls" stopProcessing="true"> 
<match url="(.*)" /><conditions logicalGrouping="MatchAny" trackAllCaptures="false"> 
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="domainname.com/(.*)\.php" /> 
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="www.domainname.com/(.*)\.php" /></conditions><action type="Redirect" url="/" redirectType="Permanent"/> 
</rule> 

What this basically says is: whatever the page or product is, when it ends on .php go to the homepage. 

Tell me more, tell me more... 

All written above is related to the redirects configured in IIS. There is a whole document about this on: 
https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference 

 

Comments

Mike Smeltzer
Tycho, great introduction into the IIS Rewrite Module and using it within DNN.

Another common redirect is forcing non-www to www. The following link should help you achieve this (* always review and test code/configuration before applying to any site *):

https://weblogs.asp.net/owscott/iis-url-rewrite-rewriting-non-www-to-www
Mike Smeltzer Wednesday, October 24, 2018 6:38 PM (link)

Comment Form

Only registered users may post comments.

NewsArchives


Aderson Oliveira (22)
Alec Whittington (11)
Alessandra Davies (3)
Alex Shirley (10)
Andrew Hoefling (3)
Andrew Nurse (30)
Andy Tryba (1)
Anthony Glenwright (5)
Antonio Chagoury (28)
Ash Prasad (37)
Ben Schmidt (1)
Benjamin Hermann (25)
Benoit Sarton (9)
Beth Firebaugh (12)
Bill Walker (36)
Bob Kruger (5)
Bogdan Litescu (1)
Brian Dukes (2)
Brice Snow (1)
Bruce Chapman (20)
Bryan Andrews (1)
cathal connolly (55)
Charles Nurse (163)
Chris Hammond (212)
Chris Paterra (55)
Clint Patterson (101)
Cuong Dang (21)
Daniel Bartholomew (2)
Daniel Mettler (165)
Daniel Valadas (21)
Dave Buckner (2)
David Poindexter (12)
David Rodriguez (3)
Dennis Shiao (1)
Doug Howell (11)
Erik van Ballegoij (30)
Ernst Peter Tamminga (79)
Francisco Perez Andres (12)
Geoff Barlow (12)
George Alatrash (12)
Gifford Watkins (3)
Gilles Le Pigocher (3)
Ian Robinson (7)
Israel Martinez (17)
Jan Blomquist (2)
Jan Jonas (3)
Jaspreet Bhatia (1)
Jenni Merrifield (6)
Joe Brinkman (274)
John Mitchell (1)
Jon Henning (14)
Jonathan Sheely (4)
Jordan Coopersmith (1)
Joseph Craig (2)
Kan Ma (1)
Keivan Beigi (3)
Kelly Ford (3)
Ken Grierson (10)
Kevin Schreiner (6)
Leigh Pointer (31)
Lorraine Young (60)
Malik Khan (1)
Matt Rutledge (1)
Matthias Schlomann (16)
Mauricio Márquez (5)
Michael Doxsey (7)
Michael Tobisch (3)
Michael Washington (202)
Miguel Gatmaytan (3)
Mike Horton (19)
Mitchel Sellers (35)
Nathan Rover (3)
Navin V Nagiah (14)
Néstor Sánchez (31)
Nik Kalyani (14)
Oliver Hine (1)
Peter Donker (54)
Philip Beadle (135)
Philipp Becker (4)
Richard Dumas (22)
Robert J Collins (5)
Roger Selwyn (8)
Ruben Lopez (1)
Ryan Martinez (1)
Sacha Trauwaen (1)
Salar Golestanian (4)
Sanjay Mehrotra (9)
Scott McCulloch (1)
Scott S (11)
Scott Wilkinson (3)
Scott Willhite (97)
Sebastian Leupold (80)
Shaun Walker (237)
Shawn Mehaffie (17)
Stefan Cullmann (12)
Stefan Kamphuis (12)
Steve Fabian (31)
Steven Fisher (1)
Timo Breumelhof (24)
Tony Henrich (3)
Torsten Weggen (3)
Tycho de Waard (3)
Vicenç Masanas (27)
Vincent Nguyen (3)
Vitaly Kozadayev (6)
Will Morgenweck (40)
Will Strohl (172)
William Severance (5)

Content Layout

Subscribe to DNN Digest

Subscribe to DNN Digest

DNN Digest is our monthly email newsletter. It highlights news and content from around the DNN ecosystem, such as new modules and themes, messages from leadership, blog posts and notable tweets. Keep your finger on the pulse of the ecosystem by subscribing.  

What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out