How to delete a post and keep its slug to refer to another post

I've 2 almost identical posts:

  1. https://webscraping.pro/reliable-open-proxies-for-business-directories-scrape/
  2. https://webscraping.pro/reliable-rotating-proxies-for-business-directories-scrape/

I want to delete first one to remove excess...

Since I might have left permalinks to it (first one) at other blogs or social services, so I want to keep its slug that is /reliable-open-proxies-for-business-directories-scrape/ and make that slug to refer to the second post. This way visitors gets redirected to the second post when hitting the slug of a deleted post.

Topic wp-delete-post slug redirect Wordpress

Category Web


You can use a plugin or edit the .htaccess file yourself (located in the root WordPress directory).

Use FTP or your host and edit your .htacess file.

Keep in mind, this code will only work if your server is run with Apache.

Enter the following code (if you know for sure your server already has the mod_rewrite module):

RewriteEngine On
Redirect 301 /reliable-open-proxies-for-business-directories-scrape/ https://webscraping.pro/reliable-rotating-proxies-for-business-directories-scrape/

The RewriteEngine is part of the mod_rewrite module in Apache. Keep in mind, the mod_rewrite module is loaded by default in Apache, BUT, if it's not loaded you will have to force the load by wrapping it with the following code.

<IfModule mod_rewrite.c>
    RewriteEngine On
    Redirect 301 /reliable-open-proxies-for-business-directories-scrape/ https://webscraping.pro/reliable-rotating-proxies-for-business-directories-scrape/
    </IfModule>

The wrapping of the IfModule seems to be a standard for rewriting non-existing links to another file. - since if the server administrator removed the mod_rewrite module from the server, then the code can break the system. Your telling apache "if mod_rewrite does exist - run this code".

Once that is setup, delete the /reliable-open-proxies-for-business-directories-scrape/ post.

You are good to go.

Of course, with editing any core files, make sure to create a backup before making edits.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.