im desperately trying to make RewriteEngine to rewrite the following pattern:
https://example.com/api/model/id/
https://example.com/staging/api/model/id/
internally to
https://example.com/index.php/model/id/
https://example.com/staging/index.php/model/id/
I already tried several suggestions from several boards but none of them worked out for me. Ideally the rule should just search for "/api/" and replace it with "/index.php/". I can’t figure out, why it is so hard to make that work, my other rules worked out fine till now…
Here is my last try:
RewriteEngine On
RewriteRule ^(.+)/api/(.+)$ $1/index.php/$2 [R=301,L]
# RewriteRule ^/api/(.*)$ /index.php/$1 [R=301,L,NC]
# RewriteRule ^(.+)/api/(.+)$ http://localhost/dev/someFolder/index.php/$2 [R=301,L]
What am I making wrong? I’m just telling the rule to make ($1)/api/($2) to ($1)/index.php/($2), that shouldn’t be that hard. Ideally the rule also shouldn’t care about whats standing before the "/api/" pattern.
2
Answers
I found a work-around, which seems to work out fine in most use-cases:
Found the answer here: htaccess remove index.php from url
Just keep in mind, that you have to put your files in a subdir named after the string you want to replace "index.php" with (e.g. to replace /index.php/$1 with /api/$1 you have to put all your files into a subdir named api).
This is just perfectly fine for my use-case.
something like this…