DNN Blogs

Written for the Community, by the Community

Redirect all URLs to the root of your site

Written By Timo Breumelhof (40F)
2020-11-18

Today I got a question by a community member if he could redirect all pages to the "Home" page in DNN.
He needs this because he is setting up a "This Website is Offline" page fallback (which can be handy in case of emergency or during upgrades)
For SEO he would like to present Google with a "Temporary Redirect" (307) for all URLs that are not the Home page, instead of a "Page not found" (404), as long as the website is offline.

The easiest way, IMO, to do this is to use a rewrite rule in web.config
You should only try this if you have access to the file through RDP of FTP as you might lock yourself out when you make a mistake when you would try adding this through the DNN interface.
You also need to make sure you have the IIS rewrite module installed (in IIS) or your site will crash when you add these rules to web.config

This is what I used (inside < system.webServer >)

<rewrite>
      <rules>
       <rule name="Redir to home" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="^[\w\.-]*?/[\w-/]+$" />
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}" redirectType="Temporary"/>
        </rule>

      </rules>
    </rewrite>

You can also add these rules in IIS manager, but copying them directly in web.config is faster and easier IMO.

Total: 5 Comment(s)
Great article, thanks! One question comes in my mind: What about the file app_offline.htm? Creating such a file in the root of the website displays it on every request keeping the original Url (therefore no redirect at all), but an HTTP error 503. If you want to load a stylesheet or display some images you have to get them from another website, but it does the trick. Is this only recommended for short downtimes (e.g. an upgrade), or could this also be a solution?
Tuesday, November 24, 2020 ·
Fro a single portal DNN install that could work too, but I find the fact that App_offline.htm also blocks CSS annoying. Especially in a multi portal installation. In that case loading css from another resource makes it all very complicated if not impossible to work with.
Tuesday, November 24, 2020 ·
Well - the file is normally not too complicated, and adding the CSS in the HTML file is not a big issue - except you have your Security Policy, which does not allow it... I worry more about Google's reaction if they get an HTTP 503 response for a longer period.
Wednesday, November 25, 2020 ·
On a multi portal / client install, I want to show a Logo for each portal / client and that's problematic using App-Offline.htm
Wednesday, November 25, 2020 ·
Good point - I stopped using these for several reasons...
Thursday, December 3, 2020 ·

Would you like to help us?

Awesome! Simply post in the forums using the link below and we'll get you started.

Get Involved