Duncan Palmer Duncan Palmer - 1 year ago 187
Apache Configuration Question

htaccess re-write for restful api

I am creating a restful based API and am stuck on htaccess re-write rules.

I am currently using this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !(.*)\.(css|js|htc|pdf|jpg|jpeg|gif|png|ico)$ [NC]
RewriteRule ^(.*)$ index.php?handler=$1 [QSA,L]

Which works, however I want it to exclude file extension directories and the current exclusion doesn't make a difference.


  • /api/object/1/list is valid

  • /api/object/test.php/js/css etc.. is not valid


Answer Source

Your RewriteCond includes a . before all the included extensions.

Remove the \. from your condition and it should work like so.

RewriteCond %{REQUEST_URI} !(.*)(css|js|htc|pdf|jpg|jpeg|gif|png|ico)$ [NC]

Do note that you will not be able to use the included extension names in your method/object name or method/object name ending with these extension names.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download