2

I am receiving multiple 404 errors for .map files which do not exist in my server logs. e.g.

/wp-includes/js/tinymce/skins/lightgray/skin.min.css.map
/wp-content/plugins/cornerstone/assets/dist/js/site/cs-head.js.map
/wp-content/plugins/cornerstone/assets/dist/js/site/cs-body.js.map

How could I set up a redirect on Nginx so that files ending .map are redirected to a blank file called 404.map

In Apache this can be achieved as follows:

RewriteEngine On
Options +FollowSymlinks

    # Prevent 404 Not Found for javascript/css source maps
    RewriteCond %{REQUEST_URI}  (\.map)$
    RewriteRule (.*)  404.map [QSA]

1 Answer 1

3

Use an error_page directive. Assuming that 404.map is placed in the document root, use:

location ~ \.map$ {
    error_page 404 /404.map;
}

If you want the 404.map file to be returned with a 200 status response, use:

location ~ \.map$ {
    error_page 404 =200 /404.map;
}

See this document for details.


In retrospect, error_page is probably not the answer you are looking for. To test for the existence of a file and return another file if it does not exist, use try_files. For example:

location ~ \.map$ {
    try_files $uri /404.map;
}

An advantage of using try_files is that the [error]...open()... messages will be suppressed. See this document for details.

Sign up to request clarification or add additional context in comments.

6 Comments

ok but will this 404 redirect, all .map files or just the ones which are missing ?
Only those that do not exist. If you want all .map files to respond with a 404, add return 404;
no I just want the ones missing .. thanks so much. My wordpress site is at var/www/html so I assume I must place 404.map in the html folder
I am still receiving errors: 2018/11/03 11:03:15 [error] 28190#28190: *26451 open() "/var/www/html/wp-content/themes/x/framework/dist/js/site/x.js.map" failed (2: No such file or directory), client: 34xxx.58, server: , request: "GET /wp-content/themes/x/framework/dist/js/site/x.js.map HTTP/1.1", host: "domain.com"
perhaps this is an issue with wordpress that interferes with nginx before your location code runs?
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.