Reputation: 2225
In Apache I have a .htaccess file in the root to rewrite URL's with an exception to a folder called admin. In the admin folder I have another .htaccess file to rewrite URL's in that folder.
How can I achieve the same using a nginx server block?
This is the snippet I currently use for URL rewriting in the root in my nginx server block:
location / {
try_files $uri $uri/ /index.php?url=$uri&$args
}
Edit:
This is what I previously had in .htaccess in the root:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^(admin) - [L,NC]
RewriteRule ^([^.]+)$ /index.php?url=$1 [L,QSA]
and this in .htaccess in the admin folder:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^([^.]+)$ /admin/index.php?strucutre_url=$1 [QSA,L]
Upvotes: 2
Views: 1276
Reputation: 49722
It seems to me that the only thing missing from your implementation is special handling for the /admin
location. I would suggest that you try this:
location / {
try_files $uri $uri/ /index.php?url=$uri&$args;
}
location /admin {
try_files $uri $uri/ /admin/index.php?strucutre_url=$uri&$args;
}
Upvotes: 3