Search code examples
.htaccesshttp-redirectmod-rewriteurl-rewritingslash

How to replace slash with questionmark in .htaccess?


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]

Solution

  • 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]