0

Let’s say I have a structure like this https://domain.com/api/rest/v1.0/, but in the folder v1.0 I have subfolders like data-model and constants.

Now let’s say I’m using mod rewrite, so all URLs that have the base URL https://domain.com/api/rest/v1.0/ get forwarded to https://domain.com/api/rest/v1.0/index.php.

Would this affect my PHP files contained in https://domain.com/api/rest/v1.0/data-model/ and https://domain.com/api/rest/v1.0/constants/?

For example, if in https://domain.com/api/rest/v1.0/index.php I try to add a file from https://domain.com/api/rest/v1.0/constants/ using require_once, would that cause some kind of redirect loop?

I’m not getting any output after the lines of code where I do the above, but am before. Similarly I’m not getting any errors/reloading of the page in the browser so am at a bit of a loss.

If this is the issue, does anyone have any pointers to a better REST file structure than just lumping all the files in the root folder?

Thanks

UPDATE

Here is my rewrite rule:

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule api/rest/v1.0/(.*)$ api/rest/v1.0/index.php?request=$1 [QSA,NC,L]

</IfModule>
Adam Carter
  • 4,741
  • 5
  • 42
  • 103

2 Answers2

0

No, neither your php files nor your directories are affected. mod_rewrite only rewrites URLs. That means that urls are only rewritten if accessed via http request (e.g. with a browser).

Probably your rewrite rules are wrong. Also check php log files for errors. What are your rules like?

Guillermo
  • 764
  • 6
  • 15
0

It turns out the solution was that my subdirectories weren’t properly added in require_once as my paths were relative. So instead of require_once 'folder/file.php' I changed my files so they now read require_once dirname(__FILE__) . '/folder/file.php'

Adam Carter
  • 4,741
  • 5
  • 42
  • 103