Problem with dynamic subdomains

#1
Hello,

I need to use dynamic subdomains, for multiple user session, so i have already a domain, is working well, when i use dynamic subdomain for exemple user1.domain.com i have a white screen with this error : Loading of the module at ... was blocked due to a forbidden MIME type ("text/html"). , The stylesheet ... was not loaded because its MIME type, "text/html", is not "text/css".

I use rewiteRules in OpenLiteSpeed like this :

# Redirect HTTP to HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Exclude request to /api/ and static files
RewriteCond %{REQUEST_URI} !^/api/
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|otf|map)$ [NC]

# Handle dynamic subdomains in the form of user<number>.domaine.com
RewriteCond %{HTTP_HOST} ^user([0-9]+)\.domaine\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/api/
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|otf|map)$ [NC]
RewriteRule ^(.*)$ /index.html [L,QSA]

# Exclude the homepage (domaine .com) from being rewritten
RewriteCond %{HTTP_HOST} ^domaine\.com$ [NC]
RewriteRule ^(.*)$ - [L]

# Rewrite all other requests to index.html (for client-side routing in a SPA)
RewriteRule ^(.*)$ /index.html [L,QSA]


the domain.com working good, it's only subdomain, the front api is in React with Vite. I think it's a problem with static files but i don't find the solution...
Can you help me?

Thank you
 

Cold-Egg

Administrator
#2
The rewrite rule section of "# Exclude request to /api/ and static files " and "# Handle dynamic subdomains in the form of user<number>.domaine.com " looks weird to me. As well as the "# Exclude the homepage (domaine .com) from being rewritten " section.

Is the subdomain site loadable if there are no rewritrules at all?
 
#3
Thank you to your answer, i tried to remove all rewriterules and the domain.com work good, but i have still a problem with this error: The stylesheet ... was not loaded because its MIME type, "text/html", is not "text/css" , so i haven't css in subdomain.
 
Last edited:
#4
Ok well, I encounter a lot of complications in the code to make this functionality and I don't have much time to continue it, so I will put this on standby, and continue on the rest, thank you anyway for taking the time
 

LiteCache

Active Member
#6
Thank you to your answer, i tried to remove all rewriterules and the domain.com work good, but i have still a problem with this error: The stylesheet ... was not loaded because its MIME type, "text/html", is not "text/css" , so i haven't css in subdomain.
Is this WordPress related? If so, check the related css files if they exist.
 

LiteCache

Active Member
#8
Ok, I'll see that when I get back to working on it. And @LiteCache , no i am not with WordPress, i am with React and Vite.
You should still check if the relevant css files exist on your server. The Mime Type error is not a real Mime Type error in most cases, but first check if the css files exist and if the paths to the css files are correct. If either of these are not the case, then I will tell you why you are getting the Mime Type error.
 
#9
Now it does it to me also for the routes, if I go from domain.com to domain.com/dashboard it works but if once during domain.com/dashboard I refresh the page I have a 404 error from the browser with the error message type MIME forbidden ("text/html"). Yes the paths exist and are correct, because it works on the first connection, it is if I want to make a direct access to domain.com/dashboard
 

LiteCache

Active Member
#10
Now it does it to me also for the routes, if I go from domain.com to domain.com/dashboard it works but if once during domain.com/dashboard I refresh the page I have a 404 error from the browser with the error message type MIME forbidden ("text/html"). Yes the paths exist and are correct, because it works on the first connection, it is if I want to make a direct access to domain.com/dashboard
What is displayed if you request a URL that doesn't exist? The LiteSpeed default error page or a custom error page generated by any CMS?
 
#12
This is what I see when I try to reach a URL that doesn't exist or even domain.com/dashboard, without any rewrite rules.

When I arrive on my home page example: domain.com, and I log into my account I am redirected to domain.com/dashboard, Until then everything works well if I refresh the domain.com/dashboard page I have the 404

If I add this rule:
# rewrite other request to index.html
RewriteRule ^(.*)$ /index.html [L,QSA]
in openlitespeed, I no longer have the 404 error and background of my application is displayed but I have the MIME type error
 
Last edited:
#14
This is the error that is displayed in the browser console

i think i found the solution, i hadded these rules in rewrite rules:

# rewrite other request to index.html
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/assets/.*$
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|jpeg|gif|svg|ico|webp|woff|woff2|ttf)$
RewriteRule ^(.*)$ /index.html [L,QSA]

So far it's working
 

LiteCache

Active Member
#15
i think i found the solution, i hadded these rules in rewrite rules:
No it isn't and I expect this answer. It seems you are using a CMS like WordPress or any other CMS. Many modern CMS catches all requests and also requests to whatever source type doesn't exists. That's why I asked you what is displayed if you request a source that doesn't exist AND if the source is NOT a HTML.

If the source code of a website points to a static source like whatever.css, then the browser (or Firefox) expecta a mime type/css , but the CMS "redirects" to a common error page that doesn't have the mime type that is expected by the browser. Again, the browser expects text/css for css, but if the quested source doesn't exist or if the source is wrong, a type/html is returned and this is the reason why you get the "wrong" mime type displayed.

You should therefore check if the requested source to the relevant css source totally exists, but note, this is neiter an OLS issue nor an issue of wrong or missing redirect rules. It is always caused by the used CMS!

FYI: The (web) server doesn't care about the mime type. If any error is displayed in the browser dev console, so it is a browser related issue, but not an issue that that is OLS or LiteSpeed related!
 
Last edited:

LiteCache

Active Member
#17
I understand, but I already answered your question a little higher by telling you that I don't use a CMS, I use React with Vite.
However, there must be a CMS controlled function on your server that tricks the browser (Firefox) into expecting an incorrect mime type.

This is not an OLS related issue!
 
#18
But why during a normal connection there is no problem I encounter the problem only if I refresh the page domain.com/dashboard, with Rect i am in SPA, maybe it is with that the problem?
 
Top