mod_rewrite

Discussion in 'Web Design and Development' started by Dunmail, Nov 28, 2010.

  1. Dunmail macrumors regular

    Joined:
    Mar 27, 2009
    Location:
    Skipton, UK
    #1
    I'm having one of those "brain's gone for a walk" days :eek:

    I'm looking at implementing a RESTful web service in which all requests are handled by a script or scripts at the root of the service, lets say this script is at: "mydomain/api/handler.php".

    Now according to the principles of REST each part of the API has its own URL such as "mydomain/api/date/" which should be handled by the script.

    Having searched the interweb I came across http://blog.teamlazerbeez.com/2010/05/25/serving-restful-urls-with-mod_rewrite/ which had the rule:

    Code:
    RewriteRule ^/api.*$ /api/handler.php [L]
    However it didn't work. RewriteRule is enabled and working in my .htaccess file. What am I doing wrong?
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Rewrite has to be turned on first:
    Code:
    RewriteEngine On
    Also try,
    Code:
    RewriteRule ^api /api/handler.php [L]
    Though part of me wonders if that's circular since you're rewriting to a path that matches the rule still.
     

Share This Page