Wordpress htaccess 301 redirect issue - wordpress

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!

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 (.*)

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.

Related

Redirect whole domain to a sub-folder on another domain in WP

I have one domain that used to have its own WP installation, say www.aaa.example.
Now the content of this has been included in a different domain in a sub-page, say bbb.example/aaa-subpage/.
Also, the old domain www.aaa.example has a DNS A record pointing to the WP Server of bbb.example.
What I want now is, that all calls go to www.aaa.example/* should be redirected to bbb.example/aaa-subpage/ no matter which sub-page on aaa.example was used. So everything should go to one sub-page in the new domain.
I have tried some 301 redirect plugins but so far no chance... all calls from aaa.example simply go to the top-level page of bbb.example.
To redirect requests to aaa.example/<anything> to bbb.example/aaa-subpage/ you would need to add the following mod_rewrite directives to the top of the root .htaccess file. Crucially, it must go before the WordPress front-controller (ie. before the # BEGIN WordPress comment marker).
# Redirect "aaa.example/<anything>" to "bbb.example/aaa-subpage/"
RewriteCond %{HTTP_HOST} ^(www\.)?aaa\.example [NC]
RewriteRule ^ https://bbb.example/aaa-subpage/ [R=301,L]
You do not need to repeat the RewriteEngine directive that should already appear later in the file (in the WordPress section).
Test first with a 302 (temporary) redirect to avoid caching issues.
You will need to clear your browser cache before testing.
Try this line in the .htaccess:
RedirectMatch ^/$ /aaa-subpage/

.htaccess 301 redirect not working on WordPress site

I'm trying to redirect domain.com/our-team/team-member/ to domain.com/about/
Here is the .htaccess code that I'm using:
RedirectMatch 301 ^/our-team/team-member(.*) ^/about/$1
However what happens with that code is that I'm redirected to http://domain.com/about/team-member/, which is essentially 404 page.
I've tried numerous variations on this htaccess rule with no luck as of yet.
Could something else be at play here? Could this be related to the way WordPress works, or something going on with the shared Go Daddy hosting environment the site is hosted in?
You have a bad target URL starting with ^. Also it is better not to mix mod_alias rules i.e. RedirectMatch with other mod_rewrite rules of WP. Use this rule just below RewriteBase line in your main WP htaccess:
RewriteRule ^our-team/team-member(/.*)?$ /about$1 [L,R=301,NC]

URL redirect on changing post date - Wordpress

I updated the date in the post. But the old URL has already gone viral and people end up in a deadlink as page not found. I tried using Simple 301 Redirect Wordpress Plugin and also Permalink Redirect WordPress Plugin. But it does not seem to work.
I want to redirect from http://www.example.com/2014/02/20/events-2014/ to http://www.example.com/2014/03/02/events-2014/
Also all my Mobile apps are synced to the website. I do not want them to get affected because of this redirection.
Try:
Redirect 301 /2014/02/20/events-2014/ /2014/03/02/events-2014/
Or using mod_rewrite:
RewriteEngine On
RewriteRule ^2014/02/20/events-2014/$ /2014/03/02/events-2014/ [L,R=301]

static to static url rewrite with htaccess with wordpress

I have a wordpress site with its own .htaccess automatically generated (because I'm using permalinks), than, my web-admin has configured apache to redirect any third level domain to my site, ie :
http://lol.example.com redirects to http://example.com
and than .htaccess with permalinks rules does the rest.
Now I want to write a rule in the .htaccess file that, when a user types a specific third level domain, redirects to a specific subfolder of my site, ie:
http://sprock.example.com/ redirects to http://example.com/mysprockfolder/
I know my question might sound weird, but I've never done this before so I'm quite confused.
Solved with that regex in my .htaccess:
Right before this comment (just in case you have WordPress installed):
# BEGIN WordPress
I've added the following:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?thirdlev\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/myfolder/ [R=302,L]
with a 302 redirect, everything is good!
it would be much easier for you to just go to your ftp manager and make a subdomain forward to a link. Or, you can make a redirect using php.
when redirecting make sure to add the http://www. or it will think you want to redirect to a part of your page on the site, also make sure that your subdomain has its own folder with its own files and images.

htaccess redirect wordpress folder change

I currently have a url of http://example.com/wordpres/
I'm going to change this to http://example.com/w/
I currently get a lot of traffic from links already out on the web. How can I redirect everything that went to /wordpress to /w ?
RedirectMatch 301 ^wordpress(.*)$ /directory/path/to/w/$1
The above line should match every request coming to your domain with 'wordress' at the start and redirect it to /w/. The '301' tells the browser (and search engines) that the page(s) have moved permenantly. The $1 exists to redirect anything after /wordpress/ and append it to the redirected URL. So if I visit http://example.com/wordpress/this-post/ I would get redirected to http://example.com/w/this-post.
Add this rule to your .htaccess file:
RewriteEngine on
RewriteRule wordpress(.*)$ /w$1
If doesnt work.. let me know... :)

Resources