Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess Resource interpreted as Stylesheet but transferred with MIME type text/html

Im trying to rewrite my existing url from http://localhost/website/article.php?id=5 to http://localhost/website/article/5 hence my htaccess code

RewriteBase /website/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule article/([[email protected]])? article.php?id=$1 [L]

What I get is Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost/website/article/css/bootstrap.min.css".

It appears that article is added to the file's url, redirecting even the file directories.

The real url should be "http://localhost/website/css/bootstrap.min.css"

Im quite new to htaccess and trying to create my own by copying from existing ones

REVISION

My actual problem is that my resources url is being renamed as well. I've eliminated lines of codes down to 2 lines

RewriteEngine On
RewriteRule article/([[email protected]])  article.php?id=$1 

but now the resources is being redirected to non existent http://localhost/website/article/js/main.js instead of http://localhost/website/js/main.js

like image 518
Emmanuel Gabion Avatar asked Dec 31 '25 17:12

Emmanuel Gabion


1 Answers

Check the URLs in the main HTML file; I suspect the browser is requesting the wrong URL before it gets to the rewrite rules. If you have relative URLs like <script src="js/main.js">, then in the non-rewritten version the browser will resolve this to http://localhost/website/js/main.js, but in the rewritten version it will resolve to http://localhost/website/article/js/main.js, because from the browser's perspective the HTML file is in the directory http://localhost/website/article/, so it resolves relative to that. If this is the issue, you can change it to src="/website/js/main.js" or src="../js/main.js".

like image 128
chridd Avatar answered Jan 03 '26 07:01

chridd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!