1

I set up Magento 2 localhost migrated from the server.

but when load frontend showing like this

enter image description here

Pub/media CSS was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff in Magento 2

how I can fix this

Magento ver 2.2.6

ubuntu 18.04

PHP 7

6 Answers 6

2

make sure .htaccess exist in pub/static

1
  1. Remove all files from var/ folder.
  2. Check for .htaccess in pub/static. If not exists, take a file from a fresh setup.
  3. Run the following commands

    php bin/magento setup:static-content:deploy -f
    php bin/magento indexer:reindex
    php bin/magento cache:clean
    
4
  • already there and i cleared cache Commented Jul 23, 2019 at 4:22
  • but magento backend is working fine Commented Jul 23, 2019 at 4:23
  • then flush cache and clear browser history then try in incognito mode Commented Jul 23, 2019 at 4:23
  • tried not working Commented Jul 23, 2019 at 5:50
1

enter image description here Same problem I am getting on my localhost so for this I have tried below methods: * replace .htaccess file in pub/static folder (no luck) * after lot search I run this commands and successfully deployed

 sudo chmod -R 777 pub/ var/ app/
 sudo php bin/magento setup:upgrade
 sudo php bin/magento deploy:mode:set production
sudo chmod -R 777 pub/ var/ app/

After these commands all errors from console gone enter image description here

4
  • superb let me try Commented Nov 23, 2019 at 13:50
  • Deploy mode in production works well... If this perfect then upvote my ans Commented Nov 24, 2019 at 14:40
  • Already updated .htaccess from default Magento 2.2.9 and run below command but got error on js files only.
    – himansu
    Commented Dec 7, 2020 at 16:22
  • can you try to change deploy mode again and run same commands, this is only cause of mode changes, also check if you are using multiple language then deploy using 'php -d -f bin/magento setup:static-content:deploy -f en_US th_TH fr_FR' Commented Dec 9, 2020 at 2:06
0

Make sure you have .htaccess in pub/static. If you don't have file take a file from a fresh setup.

Then do static content deploy and clear cache.

If It's not working make sure you have enabled mod_rewrite in ubuntu

1
  • mine backend is working fine without any problem Commented Jul 23, 2019 at 4:23
0

I had the same issue. The reason was that we added a css file which didn't exist when enabling merging css. Please check your custom js or third party js. We can also check the log.

For example, file doesn't exist.

<css src="Vendor_Module::yourcustom.css"/>
4
  • i will check ..... Commented Jul 23, 2019 at 12:08
  • @prabhakaran7 did your issue resolve? Commented Jul 26, 2019 at 3:48
  • still i'm not yet checked... Commented Jul 26, 2019 at 4:37
  • Is there any method to find error like this? I got this error only in js file
    – himansu
    Commented Dec 7, 2020 at 16:20
0

I tried all the steps like

rm -rf var/*
php bin/magento setup:static-content:deploy -f
php bin/magento indexer:reindex 
php bin/magento cache:clean

and still not worked. (These steps are required but it's incomplete)

You must have to change .htaccess file with a new one in pub/static whether exists or not.
After changing it, I ran cache:clean command again, and then it works well for me.
Most people might skip this step because .htaccess is already available in pub/static.

You can get .htaccess new one in magento official github:
https://github.com/magento/magento2/blob/2.3/pub/static/.htaccess
(It's for Magento 2.3, and you can choose your appropriate version in branch)

P.S: If u got memory exhausted error while running the commands, try with

php -dmemory_limit=5G bin/magento ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.