简体   繁体   中英

How to convert this apache rewrite into nginx correctly?

How to rewrite this Apache rule on Nginx?

<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} ^.*(pdf|epub)$
RewriteRule ^(.*)$ /wp-content/themes/divi-child/download.php?file=$1 [L]
</IfModule>

The Apache mod_rewrite rule you specified redirects requests for files ending with the suffix pdf or epub to /wp-content/themes/divi-child/download.php?file= , with the filename appended to the end of the URI.

Using nginx, this could be accomplished with the following location block within your virtual host configuration:

location ~* \\.(pdf|epub)$ { rewrite ^/(.*(?:pdf|epub))$ /wp-content/themes/divi-child/download.php?file=$1; }

This Stack Overflow question offers a bit of insight into how the pattern matching works for file extensions.

For more information, check out the nginx documentation and blog posts .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM