Static assets showing 404 not found! – Magento 2

I Reloaded the browser and bang, all my static assets were showing as 404 not found. Odd, I checked the pub/static directory, and everything had been recompiled, all ship shape and where it should be. So what was it.

Whilst on my front-end development learning rampage I was following the guides for LESS recompilation.
One section of the guide didn’t make it clear enough and what I heard was delete the pub/static directory recursively.
What I was meant to do was remove some or all the sub-directories. See my post on LESS compilation.

Fine I thought, not a problem, perform the command and away we go. From that point forward 404 not found for all JS and CSS.

It took me a while of hunting round the internet forums to realise what I had done.

By removing the pub/static directory I had also removed the hidden .htaccess file, without this file the URL rewrites do not take effect and your assets aren’t where you think they are.

Thankfully it is super simple to resolve. Head on over to Magento 2 GitHub Repository , selecting your version, grab the .htaccess file and pop it back in the root of pub/static.

Upon reloading the browser all my assets were behaving themselves and showing 200 found statuses.

Leave a Reply

Your email address will not be published. Required fields are marked *