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.
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:
- Open the SharePoint classic admin center by accessing this URL directly (replace contoso by the name of your tenant)
- Scroll down and locate the Custom Script
- Click on Allow users to run custom script on personal sites
- Click on Allow users to run custom script on self-service created sites
- 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.
- Open the PowerShell console
- 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.
- 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
- 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.