Geo Vais
Geo Vais

Reputation: 1

Remove post ID from WordPress slug into separate path segment

I have a WordPress site where all posts are in the form of:

http://example.com/category/12345-my-post-tile-is-here 

where 12345 is the post_id.

I want this to be done to the following format:

http://example.com/category/12345/my-post-tile-is-here

Is it possible using .htaccess 301 redirect or URL rewriting using regex find and replace?

I had already tried to use custom permalink structure in wordpress settings but the result is not what I looking for.

I also tried this in my .htaccess file:

redirect 301 ^(.)-(.)$ /$1/$2

but the result for http://example.com/category/12345-my-post-tile-is-here is http://example.com/category/12345/my/post/tile/is/here/

Upvotes: 0

Views: 591

Answers (1)

Vaibhav Rathore
Vaibhav Rathore

Reputation: 321

Use WordPress permalink support.

You can rewrite the permalinks from WP dashboard Settings -> Permalinks.

  1. Select custom structure
  2. Change value to /%category%/%post_id%/%postname% and save
  3. Your post will be accessible at http://example.com/category/postid/postname

Upvotes: 2

Related Questions