Can a .htaccess guru show me an example of this?

This url:

http://www.api.com/user/1

Should be translated to:

http://www.api.com/endpoint/?entity=user&id=1

This url:

http://www.api.com/user/1/?action=help

Should be translated to:

http://www.api.com/endpoint/?entity=user&id=1&action=help

etc.


Solution:

You can use this rule:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)(?:/([0-9]+))?/?$ /endpoint/?entity=$1&id=$2 [L,QSA]

Related Wordpress search:

, , , ,

Wordpress related questions and answers: