Replies: 5 comments
-
|
Hi, I kind of want to move this to a discussion for now. Do you have an |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for pointing that out — you’re right, this may not be a Next.js bug itself and I hadn’t realized that before.
These files are also injected into the page head as expected: However, the styles are still not applied. After a few seconds, the browser console sometimes shows this warning: So even though the CSS file is fetched and linked, the styles are not applied to the page. |
Beta Was this translation helpful? Give feedback.
-
|
Mmm did you manually edit this? I mean technically, you preload one thing, and then download another... that explains that warning you see.
I don't believe that. What are the response headers and contents? Content-Type header, etc, is it CSS rules coming down on that file? This still sounds like a |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
I'll move this to a discussion item for now:
|
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
-
Link to the code that reproduces this issue
https://github.com/MkeyhaniM/nextjs-apache-deplay-issue
To Reproduce
https://example.com/projects/ticketsThe page HTML renders.
Requests to /_next/static/... return responses, but the content is incorrect (HTML instead of CSS/JS).
As a result, styles are not applied and the page renders unstyled.
Notes
Screenshots can be added showing the browser console with 404s or incorrect asset responses.
Syntax highlighting for code blocks should be set to apache for VirtualHost config and bash for commands.
Current vs. Expected behavior
Next.js styles and static assets fail to load when deployed under Apache subfolder with WordPress root
Description
I am deploying a Next.js application alongside WordPress on the same Apache server. WordPress runs at the root domain (https://example.com/), and Next.js is mounted under a subfolder (https://example.com/projects/tickets).
In production, the Next.js pages render but CSS styles do not load at all. The browser downloads the files, but they contain incorrect content (often HTML from WordPress). As a result, the page renders completely unstyled
Interestingly, the Next.js 404 page loads styles correctly, which suggests the issue is related to Apache rewriting and not the Next.js build itself.
Steps to Reproduce
/projects/tickets.npm run buildand run withnpm run start.https://example.com/projects/tickets/_next/static/...are downloaded but styles are not applied.Current vs Expected Behavior
Apache Configuration
Here is the exact VirtualHost configuration I am using (with domain anonymized to example.com):
Additional Observations
The issue does not occur when running Next.js alone (without Apache/WordPress).
The issue does not occur on Netlify or Vercel.
Adding [NE] flag to RewriteRule helps with percent-encoded dynamic routes (%5Bid%5D), but CSS/JS styles still fail under subfolder deployment.
I cannot use basePath in next.config.js due to multi-project constraints.
Question:
Is there a recommended configuration for running Next.js under a subfolder with Apache (while WordPress is at root)?
How can I ensure that /_next/static/... assets are proxied correctly and styles are applied, instead of being intercepted by DocumentRoot?
Provide environment information
Which area(s) are affected? (Select all that apply)
CSS
Which stage(s) are affected? (Select all that apply)
Other (Deployed)
Additional context
The application is deployed on Cloudways (Ubuntu stack) with Apache + Nginx.
WordPress runs at the root domain (https://example.com/), and Next.js is proxied under a subfolder (https://example.com/projects/tickets).
The issue only occurs in production when served through Apache/Nginx.
On Netlify and Vercel, the same build works correctly (styles load as expected).
Locally (npm run dev and npm run start), everything works fine.
The problem is reproducible across browsers (tested on Chrome and Firefox latest).
In the Network tab, CSS files are requested and downloaded successfully, and in the rendered HTML all tags for styles are present. However, styles are not applied to the page.
Adding [NE] flag to RewriteRule fixes percent-encoded dynamic routes (%5Bid%5D), but does not solve the CSS/JS style issue.
I cannot use basePath in next.config.js due to multi-project constraints.
Beta Was this translation helpful? Give feedback.
All reactions