Exclude Files from CDN
Forge takes all your assets â images, javascript and css files and puts them onto our global CDN, whenever you deploy your site. It's part of what makes Forge special.
The Problem
But there are some files that you may prefer not to have the paths dynamically rewritten with each deployment, for example, some JSON data that you want to reference or Robots.txt for telling the search engines how you want them to interact with your site.
Right now if you try to access, for example, https://mysite.getforge.io/mydata.json you'd likely get a 404 error. Because, after deployment, this file would be located at https://cdn.getforge.com/mysite.getforge.io/12345678/mydata.json.
So you would want to exclude some files from the CDN and tell Forge to stop writing their paths each time, or at very least, handle redirects properly for the uploaded asset.
The Solution
To do this, you can use Forge-Server.
Configuration
Simply add your Forge Server configuration file to the root of your project. This file can be named forgerc.txt, .forgerc, forgerc.json, whichever you prefer.
File Exclusion Example
Files
robots.txt
mydata.json
myFolder/mydata.json
How It Works
When you exclude files from the CDN:
- Direct Access: Files remain accessible at their original URLs
- No Path Rewriting: Forge stops rewriting paths for excluded files
- Proper Redirects: Handles redirects properly for uploaded assets
- Search Engine Friendly: robots.txt and other SEO files work correctly
Common Use Cases
Files you might want to exclude from CDN:
- robots.txt: Search engine crawling instructions
- sitemap.xml: Site structure for search engines
- JSON data files: API responses or configuration data
- Security files: .well-known directory contents
- Custom assets: Files that need specific URL patterns
Benefits
Excluding files from CDN provides several advantages:
- Maintain predictable URLs for important files
- Ensure search engines can access SEO files
- Keep sensitive data files at known locations
- Enable proper API endpoint functionality
- Support custom file serving requirements
Join the Discussion
Have questions or want to share your experience? Join our community discussion to connect with other developers and get help from the Forge team.
Visit Forum Discussion