0

I am trying to redirect from

http://www.example.com:81/my/api/search?query=test

to

http://www.example.com:81/my/php/api.php?query=test

using

RewriteCond %{QUERY_STRING} ^query=(.*)$
RewriteRule ^api/search(.*)$ /php/api.php?%1 [L]

However, it doesn't work for me. Additionaly for testing htaccess rules I use http://htaccess.madewithlove.be/.

Possibly even better would be to check if request starts from ^api and it's GET type (I guess using RewriteCond %{REQUEST_METHOD}) then redirect to /my/php/api.php?[query params here]

Anyone can point me into right direction?

Cezary Tomczyk
  • 584
  • 1
  • 7
  • 14

1 Answers1

1

If your .htaccess is located in /my/ directory then you can use:

RewriteEngine On
RewriteBase /my/

RewriteCond %{QUERY_STRING} ^query=.
RewriteRule ^api/search/?$ php/api.php [L]

QUERY_STRING will be automatically carried over to target URL.

anubhava
  • 761,203
  • 64
  • 569
  • 643