What if the WP_REST actions not working after deployed to different server?

WordPress have a important feature called WP_REST to create customised api actions

In some cases these actions won’t work properly when you switch the code to different server. It will simply through 404 error code.

Solution 1:

Check your apache server config file for mod_rewrite module is enabled or not.

Also refer. how to check mod_rewrite enabled status.

Solution 2:

Check the .htaccess file content. Make sure you the following code in your .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

If your projects accessed via sub folder from the main domain name, slightly change your .htaccess file as below

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /sub_folder/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /sub_folder/index.php [L]
</IfModule>

Now your issue must be resolved!

Updated: March 13, 2024 — 10:15 am