robertgombos
robertgombos

Reputation: 27

Wordpress htaccess 301 redirect issue

could anyone help me please with the code that I need to insert in my blog's .htaccess to redirect everything from:

https://www.example/blog/wp-json/WHATEVERcomesHERE 

to:

https://www.example.com/blog/

The .htaccess file resides in https://www.example/blog/ (since example.com is another story, and WP is installed on /blog/). Thanks!

Upvotes: 0

Views: 282

Answers (2)

Mo'men Mohamed
Mo'men Mohamed

Reputation: 1909

Here is a simple redirect, You can add this code at the end of your .htaccess file

RewriteEngine On
RewriteRule ^blog/wp-json/(.+)$ https://www.example.com/blog/ [R=301,L]

Please keep in mind that a small mistake in your .htaccess code can make your WordPress site inaccessible, and it may start showing Internal Server Error.

That’s why it is important that you backup your .htaccess file before making any changes.

Another way (Recomended)

Create Redirects in WordPress using Plugins

You can use Redirection plugin. Install and activate the plugin. Once activated, visit Tools » Redirection to setup your redirects.

Also Simple 301 Redirects , it makes 301 Redirects simple. Simply install and activate the plugin and then visit Settings » 301 Redirects to add your URLs.

Upvotes: 0

Charles
Charles

Reputation: 1122

This should do what you need. If you want to pass the value of "WHATEVERcomesHERE" in the redirect you can do so using $1 in the URL you want to redirect to (i.e. https://www.example.com/blog/$1).

RewriteEngine on
RewriteRule ^blog/wp-json/(.+)$ https://www.example.com/blog/ [R=301,L]

Also, the current rule would redirect /blog/wp-json/sada but not /blog/wp-json/. If you want it to redirect when there isn't anything after wp-json then change (.+) to (.*)

Upvotes: 1

Related Questions