.htaccess redirect and rewrite url if REQUEST_URI starts with specific path

arvil

I am working on a Wordpress site, it requires a plugin that needs to access the API endpoint of WP.

It wants to access the site's:

http://myhost.test/wp/wp-json/erp/v1/hrm/employees/1\?include\=department,designation,reporting_to,avatar,roles

but changes to the folder structure, causes the real, and actual link should be:

http://myhost.test/wp-json/erp/v1/hrm/employees/1\?include\=department,designation,reporting_to,avatar,roles

as you can see, there should be no /wp at the start of the %{REQUEST_URI}

I am trying to make this work: but it won't redirect the request:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/wp/wp\-json/
RewriteRule ^/wp/wp\-json(.*) /wp\-json$1 [L,R]

I do not understand what I am doing wrong,

I am catching everything after ^/wp/wp-json then forward it to ^/wp-json

What is going on?

Regards,

Michael Berkowski

Using mod_rewrite in .htaccess context vs a <Directory> or <VirtualHost> context each have slightly different requirements in how the patterns are parsed. Most importantly to your situation, in .htaccess the first argument to RewriteRule is not matched against a leading slash / because the pattern is considered relative to the directory it is in.

Remove the leading / from your RewriteRule matcher argument:

RewriteRule ^wp/wp\-json(.*) /wp\-json$1 [L,R]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related