How to Redirect WordPress Posts by IDs to Full URLs

raccoon-mascot

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: stosu.com/?p=1453.

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 stosu.com/7753.

Liked this post?

Subscribe to our newsletter to receive early notification of new posts and deals:

Next Post »« Previous Post

Leave a Reply

Your email address will not be published. Required fields are marked *