Redirect Wordpress Permalink in htaccess - wordpress

I want to change the permalink structure of my site from /%postname%/ to /%category%/%post_id%/%postname%/ , and have the old backlinks redirect to the new structure (currently getting 404's). I have tried a couple of different redirection plugins (Redirection, 301 Simple Plugins) and I can't get them to work.
Can someone show me the rule to put in the htaccess file instead?
Thanks!

If you know the explicit category and post_id for a given postname, then you can create the redirects individually:
Redirect 301 /example-post-name-to-redirect/ /example-category/1234/example-post-name-to-redirect/
or using mod_rewrite (note, these rules must be before your wordpress rules:
RewriteRule ^example-post-name-to-redirect/$ /example-category/1234/example-post-name-to-redirect/ [L,R=301]
But the better solution is just using wordpress to do this for you, have you tried: UrbanGiraffe Redirection plugin, Scott Yang's Permalink Redirect WordPress Plugin, or Yoast's Permalink Redirect WordPress Plugin?

On the Redirection Wordpress Plugin you must add your old structure to Site->Permalink Migrations, something like this:
/%year%/%monthnum%/%postname%/
On the .htaccess file you must use regex like this one:
RedirectMatch 301 /^/\d{4}/\d{2}/(.*) https://yourdomain.com/$1/

Related

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!
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.

Wordpress 301 Redirect

I have got one Wordpress blog site and I use permalink as:
%category%/%postname%.html
I want a change as:
%postname%.html
And now old urls (https://www.example.com/category/post-name.html) 301 redirect to (https://www.example.com/post-name.html).
How can I redirect with use .htaccess file?
Just go to wp-admin, then /settings, then /permalinks and select "Post name". More info on that here: https://codex.wordpress.org/Using_Permalinks
For 301 redirects you can write your own to your htaccess file but this is probably not as easy as using a plugin like Simple 301 Redirects.

Wordpress .htaccess rewrite

I have wordpress installed. I want to customize permalink as following:
Category: http://my-domain/{category-name}/
Post: http://my-domain/{category-name}/{postname}/
Post with params: http://my-domain/{category-name}/{postname}/{param1}/
Post with params: http://my-domain/{category-name}/{postname}/{param1}/{param2}/
Can I do only use .htaccess?
Thanks!
P.S: Sorry for my bad English.
In the admin dashboard, customize the permanent links to
http://my-domain/%category%/%postname%/
In Wordpress you can do this through backend. Go to Settings-->Permalinks-->Custom Structure and insert:
%category%/%postname%
You can refer here
If you wish to use other subfolders you need to create .htaccess file (if you are using Apache) in your root folder and use url rewrite like this:
RedirectMatch 301 /old-directory/(.*) /new-directory/
Be sure mod_rewrite Apache module is enabled.

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]

Changing Permalinks

I want to change my permalinks from /%year%/%monthnum%/%day%/%postname%/ to /%postname%/
but when I added the following to the .htaccess file, posts didn't redirect the way I thought they would:
RedirectMatch 301 /dddd/dd/dd/(.*) /$1
What do I need to put into my .htaccess file to make it work?
My site is http://SweatingTheBigStuff.com
I think everyone is missing the point here - I think #Daniel has changed his permalinks, and now wants to redirect old permalinks.
The problem is your RedirectMatch regex is only matching a literal 'd', not digits.
Personally I would use this instead;
RedirectMatch 301 ^/[0-9]{4}/[0-9]{2}/[0-9]{2}/(.+)$ /$1
However, #markratledge is right in saying that there are issues with using just the postname.
You don't go into any code to change permalinks; that's changing WP core files, you'll break things and you'll loose your changes on an upgrade. It's much easier than that: go to Wordpress/Dashboard/Setings/Permalinks. If your .htaccess isn't writable, you'll get a warning.
And, using only the postname in permalinks is not recommended for performance reasons: Using only Postname in Permalinks « WordPress Codex
A relevant answer to TheDeadMedic,
You could use a plugin called Redirection to redirected your old permalinks to new permalinks.
But if you need to change your permalinks from the old version to a new version, then follow markratledge's advice

Resources