How to Redirect WordPress Posts by IDs to Full URLs


I have previously written about creating and using shortlinks for WordPress posts. The simplest way to use a shortlink in WordPress is to make use of the specific ID of a post, like this:

All you need to know is the ID of the post.

Finding Out the ID of a Post

To find out the ID of a post, go to WordPress Dashboard > Posts. Once there, hover your mouse over the name of a post — this will show the following links below that post: Edit, Quick Edit, Trash, View.

Now, hover your mouse over the Edit link to reveal the ID of that post.

Finding out a WordPress post's ID

Finding out a WordPress post’s ID

The ID of the post will be displayed as part of a longer URL, such as this:

Of course, instead of ID there will be an actual ID number specifying the post.

Redirecting to Post URL by Post ID

Unfortunately, simply using the post ID as a shortlink will not work natively in WordPress.

To be able to use the following type of shortlinks:

…you need to make a slight change to your server’s root .htaccess file.

It is just one line that needs to be added between the <IfModule mod_rewrite.c> and </IfModule> tags.

Namely this one:

If the above mentioned tags are missing from your .htaccess file, then you need to add all of the following lines to make this work:

Once you add this to your .htaccess file, you will be able to use the shortest possible versions of your WordPress posts’ links.

For example, the shortlink to the post you are reading right now, is

Liked this post?

Subscribe to our newsletter to receive early notification of new posts and deals:
[mc4wp_form id=”45″]

Next Post »« Previous Post