Francesco
Francesco

Reputation: 25239

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?

Upvotes: 1

Views: 90

Answers (1)

Richard Smith
Richard Smith

Reputation: 49722

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.

Upvotes: 1

Related Questions