Mixed Content Page: requested an insecure stylesheet error

Mixed Content Page: requested an insecure stylesheet error

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Mixed Content Page: requested an insecure stylesheet error

When you encounter the "Mixed Content" warning in your browser console, it means a secure HTTPS page is attempting to load a resource—like a CSS file or JavaScript script—over an insecure HTTP connection. Modern browsers block these requests automatically to protect user privacy and integrity. If your site works perfectly over http:// but breaks completely (no styles, no scripts) when switched to https://, the culprit is almost always server-side redirection logic that forces static assets into an insecure protocol.

The error log explicitly states: "The page at https://... was loaded over HTTPS, but requested an insecure stylesheet." This confirms the browser successfully fetched your main HTML document via a secure connection, but when it tried to fetch the linked stylesheets (e.g., style1.css), the server responded with an HTTP redirect.

The Root Cause: Absolute Redirects vs. Relative Paths

In your specific case, the issue lies in the .htaccess configuration. You noted that removing the file resolves the problem, which points directly to a rewrite rule inside it.

The critical lines causing this behavior are:

RewriteCond %{SERVER_PORT} ^443$
RewriteRule (.*) http://www.example.com/$1 

This logic operates as follows:

  1. %{SERVER_PORT}: This variable holds the port number of the incoming connection. If a user accesses your site via https, the server receives the request on port 443.
  2. The Condition: ^443$ matches requests specifically coming from HTTPS.
  3. The Rule: When the condition is met, the rule rewrites the entire URL ((.*)) to start with http:// instead of https://.

When your HTML page references a CSS file using a relative path (e.g., /includes/templates/classic/css/style1.css), the browser constructs the absolute URL based on the protocol of the main page. However, because the .htaccess rule intercepts the request before the static file handler processes it, it forcibly redirects any resource requested over port 443 back to port 80 (HTTP).

Fixing the .htaccess Configuration

To resolve this, you must ensure that resources are served over the same protocol they were requested on. The safest approach is to remove the unconditional redirect from HTTPS to HTTP for all requests.

If you rely on SSL termination at a load balancer (like Nginx or Apache in front of PHP-FPM) and want to force HTTPS globally, you should only redirect HTTP traffic to HTTPS, not vice versa. You should remove or comment out the block that forces http:// when the port is 443.

Additionally, look at your other rewrite rules. The line:

RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

is a global redirect to HTTP. Unless you are specifically trying to force an HTTP downgrade (which is generally discouraged), this will break your secure site. If your goal is to enforce HTTPS, the logic should be inverted:

# Force HTTPS only if the original request was HTTP
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Handling Static Assets Correctly

It is important to understand that modern web servers (Apache and Nginx) are designed to serve static files (CSS, JS, images) without invoking the application logic. The .htaccess file should not be rewriting paths for static assets unless there is a specific routing requirement.

If you have multiple rewrite rules in your file, ensure they do not inadvertently catch static files. A common mistake is placing general rewrite rules before checking if the file exists. Your provided config includes this standard check:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

This is good practice; it ensures that if a physical file like style.css exists, Apache serves it directly and skips the rewrite engine. However, if your redirect rules appear before this check or are unconditional (like the port 443 rule), they will override the direct file serve.

Security Implications of Mixed Content

Allowing mixed content is a security risk. While your HTML loads over HTTPS, loading an insecure stylesheet means the browser establishes an unencrypted connection for that specific resource. An attacker controlling the DNS or a network proxy could modify style1.css to inject malicious scripts or alter the layout to perform phishing attacks. Since the main page appears legitimate (served via HTTPS), users are less likely to suspect the compromised resource.

To maintain a secure site, all resources—stylesheets, JavaScript, fonts, and images—must be served over HTTPS if the main document is loaded over HTTPS. This ensures that the integrity of the entire page chain is preserved.

For those managing Laravel projects or similar frameworks where URL rewriting is complex, ensuring that your web server configuration (.htaccess or nginx.conf) respects the X-Forwarded-Proto header and serves static assets directly without protocol manipulation is essential for maintaining security best practices.

Our network