Reputation: 757
I'm moving from Apache to nginx, have many .htaccess files throughout the site (e.g. example.com/.htaccess, example.com/folder/.htaccess).
An example of a .htaccess file I have is:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^do_ajax\.php /wp-admin/admin-ajax.php [QSA,L]
</IfModule>
# END WordPress
And the nginx conf equivalent is something like:
# BEGIN WordPress
rewrite ^/ajax /wp-admin/admin-ajax.php last;
# END WordPress
Since the nginx configuration goes in /etc/nginx/nginx.conf and targets all files instead of the folder, is there anything I can do to make it target the particular folder it's meant for (e.g. if the above folder for www.example.com is located at /usr/share/nginx/html/example/)?
Upvotes: 0
Views: 1254
Reputation: 143926
You need to include the "folder" part in the match:
rewrite ^/folder/ajax /wp-admin/admin-ajax.php last;
since these nginx rules are not per directory context. But if you need to group them together you could use the location
block:
location /folder/ {
rewrite ^/folder/ajax /wp-admin/admin-ajax.php last;
}
if you want to group them together, but you still need the /folder/
in front of the regex.
Upvotes: 0