I did some .htaccess code to make PHP API route.
It's working in apache ( local server )
Options -MultiViews
RewriteEngine On
#What does this mean??
RewriteRule ^(.+)$ quizAPI.php?url=$1 [QSA,L]
But when I moved mine code to server it's not working because it not an apache. I am trying to make API URL Like this :
example.com/users/get/
#What does this mean?? RewriteRule ^(.+)$ quizAPI.php?url=$1 [QSA,L]
Not quite sure of the difference between Apache and LiteSpeed in this respect (perhaps a difference in how the request is mapped to the filesystem?), however, this is only working on Apache arguably by "chance". The reason being, when you request /users/get/
the above rewrites as follows:
/user/get/
quizAPI.php?url=user/get/
L
flag)quizAPI.php?url=quizAPI.php&url=user/get/
(due to the QSA
flag)L
flag)quizAPI.php?url=quizAPI.php&url=user/get/
(again)This still "works" (on Apache) since the url
parameter (as read by your PHP script) is still user/get/
(the 2nd instance of the url
param overwrites the first in the $_GET
array). And there is no rewrite-loop. LiteSpeed, however, might be triggering another pass by the rewrite engine (causing a "loop").
However, we need to prevent that second pass by the rewrite engine (on Apache as well) and I would expect this would resolve the issue on LiteSpeed as well.
One way is to prevent the rewrite from occurring when quizAPI.php
is requested. For example:
RewriteCond %{REQUEST_URI} !^/quizAPI\.php$
RewriteRule (.+) quizAPI.php?url=$1 [QSA,L]
However, this still rewrites all static assets (CSS, JS, images, etc.) to your script (which I'm assuming must "OK", since it "works" on Apache), but this might need further modification in the future.
Alternatively, if your URLs that you pass to quizAPI.php
don't contain dots (that otherwise delimit file-extensions) then it would be simpler to only match URLs that don't contain dots instead (which avoids the need for the preceding condition). For example:
RewriteRule ^([^.]+)$ quizAPI.php?url=$1 [QSA,L]
And this naturally avoids rewriting requests for your static assets as well.