How to replace slash with questionmark in .htaccess?

Viewed 78

Somehow i could nowhere find a solution how to convert

https://example.com/api/command

to

https://example.com/api?command

in a .htaccess-file. Anyone a quick solution to this? It should only internally redirect.

Here what does not work:

RewriteEngine On
RewriteRule ^api/(.*)?$ api?$1 [NC,QSA]
1 Answers

Have your htaccess file in following way, written and tested with shown samples. Also please make sure you clear your browser cache before testing your URLs.

RewriteEngine ON
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(api)/(.*)/? $1?$2 [NC,L]
Related