2

I have site I am running on localhost http://example and I have directory in the root that contains my api so it's http://example/api

In the api folder I have my root directory for the api which is public directory. so /api/public/....

I want to have a .htaccess that redirects the user to the public directory when they hit http://example/api/{api parameters}. So I can have a clean url without having to write this http://example/api/public/{api parameters}

I tried this but to no avail

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/api
RewriteRule ^api/(.*) /api/public/$1 [L]

I got the above from a SO post but still could not get it to work.

Community
  • 1
  • 1
bos570
  • 1,505
  • 2
  • 23
  • 45

1 Answers1

0

Try using:

RewriteEngine On
RewriteBase /api/public/

Quoting a stack overflow answer, "By having the RewriteBase there, you make the relative path come off the RewriteBase parameter."

With this method I believe you will have to rewrite all paths that don't fall under the base directory. If this is a problem, you could create a rule for each page.

Update: You might be able to write a rule that checked for files at that path before/after it checks for the relative path.

Community
  • 1
  • 1
atoms
  • 2,993
  • 2
  • 22
  • 43