I need help with static files not loading on cPanel.

For the past 2 days I have been trying to get apache to serve the static files but it returns an error

I am using cPanel shared hosting. I do not have access to console only run script button.

error from console from google chrome:

style.css was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).

Here are my settings:

I am redirecting passanger_wsgi to wsgi.py in Univerproject(folder where settings.py is).

Settings.py in cPanel

# Static files (CSS, JavaScript, Images)

STATIC_URL = ‘/static/’

STATIC_ROOT = ‘/home/ (my user name)/public_html/staticfiles/’

STATICFILES_DIRS=[BASE_DIR / “static”]

MEDIA_URL = ‘/media/’

MEDIA_ROOT = ‘/home/ (my user name )/public_html/media/’

.htaccess in cPanel

Alias /static/ /home/(my user name )/public_html/staticfiles/

# Serve static files directly

<Directory “/home/(my user name )/public_html/staticfiles”>

Require all granted

Alias /media/ /home/(my user name )/public_html/media/

# Serve media files directly

<Directory “/home/(my user name )/public_html/media”>

Require all granted

# Protect the project folder

<Directory “/home/(my user name )/ (my domain as folder )”>

Require all granted

Files are in public_html/staticfiles I checked.

filestructure:

logs:App 337097 output: [ pid=337097, time=2025-08-22 12:00:33,916 ]: Not Found: /static/css/style.css

his is a common issue with Django on cPanel. The problem is that Apache is serving your static files with the wrong MIME type (text/html instead of text/css). Here are several solutions to try:

Solution 1: Fix .htaccess Configuration

Solution 2: Add MIME Type Definitions

Solution 3: Check File Permissions

Solution 4: Verify Static File Collection

Solution 5: Alternative .htaccess Approach

Also Checks:

  1. Verify file paths: Make sure the paths in your Alias directives exactly match where your files are located.

  2. Clear browser cache: The error might be cached in your browser.

  3. Check file existence: Ensure the CSS files actually exist in the staticfiles directory.

  4. Test with direct URL: Try accessing the CSS file directly via URL to see if Apache serves it correctly.

Note: This is not the only cause for this issue. This error can also be caused by Django returning a 404 page when the request is being issued for the css file. In this case the root issue is that Django is attempting to serve the file instead of Apache.

Thank you for the list. The browser returns a 404 page. My guess is Apache doesn’t even find the files. Because there is no error type mismatch on the 404 page. However I do not see where in the path I have made a mistake. I double checked the files are there. I cleared the cache as well.

Is there any documentation I can read about how to test if this is the cause?

Look at the 404 page being returned. Is it the Apache page or the Django page? The origin of the page will tell you which process handled the request.

It is a the Django page. Also I removed urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) from urls.py on the production server, but it still serves the Django 404 page.

This means that you don’t have Apache configured to serve your static urls from their proper directory.

Thank you KenWhitesell and iman-mohadesi

Found out the issue was cPanel shared hosting was set to not allow Apache to serve any files even in subdomains of Public_html. After help from the support team of the shared hosting I was able to get static files to load.