Reputation: 1076
I'm new to the .htaccess things, I'm trying to make something like that.
localhost/easyApy/?tablename=%tablename% => localhost/easyApi/%tablename%
localhost/easyApy/?tablename=%tablename%&action=get&id=%id% => localhost/easyApi/%tablename%/get/%id%
localhost/easyApy/?tablename=%tablename%&action=delete&id=%id% => localhost/easyApi/%tablename%/delete/%id%
localhost/easyApy/?tablename=%tablename%&action=update&id=%id% => localhost/easyApi/%tablename%/update/%id%
localhost/easyApy/?tablename=%tablename%&action=add => localhost/easyApi/%tablename%/add
Thanks! :)
Upvotes: 0
Views: 62
Reputation: 42885
You are most likely looking for something like that:
RewriteEngine on
RewriteRule ^/?easyApi/(\w+)/get/(\d+)/?$ /easyApi/index.php/?tablename=$1&action=get&id=$2 [L]
RewriteRule ^/?easyApi/(\w+)/delete/(\d+)/?$ /easyApi/index.php/?tablename=$1&action=delete&id=$2 [L]
RewriteRule ^/?easyApi/(\w+)/update/(\d+)/?$ /easyApi/index.php/?tablename=$1&action=update&id=$2 [L]
RewriteRule ^/?easyApi/(\w+)/add/?$ /easyApi/index.php/?tablename=$1&action=add [L]
RewriteRule ^/?easyApi/(\w+)/?$ /easyApi/index.php/?tablename=$1 [L]
Note: this assumes that your id
's are of numeric type.
That rule set will work likewise in dynamic configuration files or in your http servers host configuration.
Keep in mind that exposing your database in such a transparent manner is a major security issue. And no, the fact that this is just meant to be used "locally" is not a good reply to that. Not at all.
And a general hint: you should always prefer to place such rules inside the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those files are notoriously error prone, hard to debug and they really slow down the server. They are only provided as a last option for situations where you do not have control over the host configuration (read: really cheap hosting service providers) or if you have an application that relies on writing its own rewrite rules (which is an obvious security nightmare).
Upvotes: 1