Reputation: 323
I have an .htaccess file that redirects requests to a php API using the directive below.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule api/v1/(.*)$ api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>
The RewriteRule seems to be causing a redirect recursive error. I have the exact same directive and API running on another Apache server with the same hosting company with no issues at all in production. Both sites run from out of a subdomain, each on a seperate shared hosting account.
Folder structure is the same on both shared hosts:
├── root
│ ├── subdom
│ │ ├── .htaccess
│ │ ├── api
│ │ │ ├── v1
│ │ │ │ ├── index.php (API entry point)
Here is the error that is caught in the error log, no error gets caught by the index.php in the API.
Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
I've compared phpinfo outputs, all the settings and versions are the same.
Tests:
This method fails on one of the shared hosting accounts
subdom.domain.com/api/v1/endpoint/arg
This method works on both shared hosting accounts
domain.com/subdom/api/v1/endpoint/arg
This method hits the api without errors on both hosting accounts
subdom.domain.com/api/v1/
Upvotes: 1
Views: 207
Reputation: 18671
Try to add:
RewriteBase /
Or to change (with /
):
RewriteRule api/v1/(.*)$ /api/v1/index.php?request=$1 [QSA,NC,L]
Upvotes: 1