0

I'm using Restler for building REST API on an Apache Server and I have some url rewrite problems.
Here are my directories :

/api:
  /vendor
  ...
  .htaccess (1st level)
  /public :
    /examples
    /test
    /src
    .htaccess (2nd level)
    /explorer :
      /css
      /images
      /lib
      index.html

Now, here is what I want :
1) I want an invisible "public" directory from the others.
For example a request like GET mydomain.com/api/data will pick it directly into mydomain.com/api/public/data

2) I want the root of "public" directory to be explorer/index.html but this file load a lot of resources in a relative way and sometimes it don't load.

So basically I want to access to /api/public/explorer/index.html with all the resources loaded if I only try to access to : mydomain.com/api

Here is what I have now :

Options +FollowSymLinks
AddDefaultCharset UTF-8

RewriteEngine On
RewriteBase /api/
RewriteCond %{REQUEST_URI} !^public/
RewriteRule ^(.*)$ /api/public/$1

For the first-level .htaccess, which seems to works pretty well

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^/$ explorer/ [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule mod_php5.c>
    php_flag display_errors On
</IfModule>

For the second-level .htaccess

Any recommandations ? Thank you

cocoggu
  • 401
  • 7
  • 18

1 Answers1

1

This rule:

RewriteRule ^/$ explorer/ [QSA,L]

Isn't going to work, because requests that reach that rule will have the leading slash stripped off:

RewriteRule ^$ explorer/ [QSA,L]

But I'm not exactly sure that's what you want either, because in order to get to that rule, you'd need to go to:

http://mydomain.com/api/

If that's what you want, then you just need to remove that leading slash.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • Thank you ! Just one thing left, the assets (css, images, js) are not loaded. In the chrome console for example for one js file : http://mydomain.com/api/public/lib/handlebars-1.0.rc.1.js So it's missing the explorer/ ! – cocoggu Dec 28 '13 at 16:31
  • Notice that i just remove the [L,R=301] from my original post cause it was displaying the final URL, which I don't want. – cocoggu Dec 28 '13 at 16:51
  • @cocoggu Not sure what you can do about fixing broken links. Relative URL links and messing with removing path nodes in mod rewrite will *never* mix. You either have to fix all of your links to use a common base URL or move your assets so they are accessible using the relative URL – Jon Lin Dec 28 '13 at 20:42