How to host static HTML sites on modern SharePoint site collections

SharePoint can be used as a web server to host sites in your organization that are not connected to SharePoint directly, however with the modern experience this is blocked by default.

In this article I’ll explain you how to bring back this awesome functionality to modern Communication and Team sites.

Host static sites modern SharePoint

The hosting of sites in SharePoint will require you to upload all the HTML files with the ASPX extension, however this type of file is blocked and requires custom scripts to be enabled at the tenant level and site collection level.

If you want to learn more about custom scripts before proceeding with the activation have a look to this article.

Enabling custom scripts in modern SharePoint

Before getting custom scripts running on your modern site, you need to make sure it is already enabled at tenant level. To verify or enable it, you should follow these steps:

  1. Open the SharePoint classic admin center by accessing this URL directly (replace contoso by the name of your tenant)
    https://contoso-admin.sharepoint.com/_layouts/15/online/TenantSettings.aspx
  2. Scroll down and locate the Custom Script
  3. Click on Allow users to run custom script on personal sites
  4. Click on Allow users to run custom script on self-service created sites
    Host static sites modern SharePoint
  5. Click OK to save the changes

Note: Changes to the tenant settings can take up to 24 hours to be applied.

In order to enable the custom script in your modern site collection you need to install the latest version of the PnP PowerShell module, more information about how to do it can be found here.

  1. Open the PowerShell console
  2. Execute the following script (replace the URL in the connect by the link of your site collection)
    Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/StaticSite 
    $site = Get-PnPSite 
    Set-PnPSite -Identity $site.URL -NoScriptSite $false
    

Once the execution ends, your modern SharePoint site is ready to host your static HTML site.

Hosting HTML and ASPX files in modern SharePoint

Before uploading the files to SharePoint, you must rename all HTML files to ASPX, your operating system may warn you about changing the file type, but you can proceed without issues.

  1. Choose the location where to store the static HTML site, you can create a new document library or use the Documents library that exists by default in all site collections
  2. Upload all the ASPX files and other related assets like, CSS, JavaScript and Images
  3. Click in the home page of your site

You are ready to navigate and share the link with others inside your organization, in the following animation you can see a static site hosted in SharePoint being displayed in the browser.

Host static sites modern SharePoint


9 Responses to “How to host static HTML sites on modern SharePoint site collections”

  1. Swapna

    April 12, 2022

    Hello, Joao Ferreira

    The approach you explained in this article to host static Sharepoint site/aspx pages by uploading all the files works great for our scenario. I would like to know if there are any known issues we should be aware of if we use this approach. As MS keeps changing the Sharepoint layouts/features/functionalities, we want to make sure we are safe to use this approach.

    Thanks

    Reply
    • João Ferreira

      April 27, 2022

      Hello,

      I don’t see any issue of using this solution other than activating the custom scripts to make it work.
      Even with new features coming to SharePoint they should not impact your static site.

      Have a nice day 🙂

      Reply
  2. David

    October 5, 2022

    I have followed your instructions (above) to the letter (I think) … I don’t get errors when executing the commands in PowerShell … originally had to overcome some barriers … but it sorted … so
    Scripted open for use in Sharepoint Admin ? Check
    PowerShell NoscriptSite $false ? Check

    My static (which some menu slider scripting) still not rendering correctly.

    I’m hoping there is a step missing?? Can you confirm please?
    Thx

    Reply
    • João Ferreira

      October 18, 2022

      Hi David,

      If the page is rendering and the menu that relies on script does not work properly you may need to fix the path to the JS files in your HTML file.
      Do you see any script error when you press F12 in the static site?

      Have a nice day 🙂

      Reply
  3. Stefan B

    October 6, 2022

    Thanks for the guide. I have tried it but Sharepoint only downloads my index.aspx file. Any advice?

    Reply
    • João Ferreira

      October 18, 2022

      Hi Stefan,

      Please make sure you have enabled the custom scripts for the tenant and site collection and give it enough time for the change to be applied.
      The behaviour you are describing usually happens when the custom scripts are not enabled.

      Have a nice day 🙂

      Reply
  4. Bernarddo

    October 14, 2022

    Hello Joao,
    we have a big collection of web sites mixing static html pages with aspx from SharePoint to migrate. They contain a massive amount of pages (dozens of thousands of html pages of technical documentation…)
    If I understand well (I’m not an IT man), if we follow your tips, the small JavaScript present in some html pages and in some SharePoint Master-page will still work?
    By the way, is there still no other way to use these statics sites without changing all the extension to aspx?
    Thanks in advance.

    Reply
    • João Ferreira

      October 18, 2022

      Hi Bernarddo,

      If those pages are SharePoint pages from classic sites, then this method will not work for you as in modern SharePoint you will not have the masterpage required for the page to page to render.
      If what you have are static HTML sites, all you have to do is rename the HTML files to ASPX and upload all the assets to a modern site collection following the instructions in the article, don’t forget also to upload the JS and CSS files required for the page to work and update the paths in the HTML if needed to point to the new location.

      Hope this helps, have a nice day 🙂

      Reply
  5. Bernarddo

    October 18, 2022

    Thanks Joao, I will let you know how we’ll get out of this.
    Have a nice day too.

    Reply

Leave a Reply to Bernarddo


I've been working with Microsoft Technologies over the last ten years, mainly focused on creating collaboration and productivity solutions that drive the adoption of Microsoft Modern Workplace.

%d bloggers like this: