Skip to content

Instantly share code, notes, and snippets.

@GeekPress
Created April 25, 2018 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GeekPress/372d5072dddf2763063615a489fa5976 to your computer and use it in GitHub Desktop.
Save GeekPress/372d5072dddf2763063615a489fa5976 to your computer and use it in GitHub Desktop.
Nginx skip WordPress 404 handling for static files
if (-f $request_filename) {
break;
}
if (-d $request_filename) {
break;
}
if ($request_uri ~ "(robots\.txt|sitemap\.xml(\.gz)?)") {
break;
}
if ($request_uri ~* \.(css|js|html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$) {
return 404;
@adamisrafil
Copy link

Where does this code go to work?

@GeekPress
Copy link
Author

Into the NGINX configuration file.

@finalwebsites
Copy link

Hi,

this should be a location directive in Nginx?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment