Francesco Francesco - 3 days ago 6
Apache Configuration Question

Apache to Nginx: how to translate htaccess rules

This is one of many rules i have in my htaccess

RewriteRule ^categories/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ types.php?type=$1&id=$2 [L]


Question 1: how do you translate that rule?

Question 2: does nginx have file similar to htaccess or is just the nginx.conf to edit?

Answer

Try:

rewrite ^/categories/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ /types.php?type=$1&id=$2 last;

The rewrite rule should translate easily, except that nginx uses a leading / on all URIs.

The nginx.conf is the starting point, but many installations use include directives to pull in configuration from other files.

The rewrite rule can be placed at server block scope or within a location block that processes URIs beginning with /categories.

See this document for rewrite syntax.

Comments