How to redirect url with year and date to just post name in wordpress?


There are three ways to change the URL structure of your WordPress posts.

  1. By changing permalinks in the settings to post name
  2. Adding an entry to the .htacces file using the rewrite.
  3. Adding redirect rule to .htaccess

The first method is pretty easy. Just go to Settings–> Permalinks and change to post option. You can also mention your custom structure.

The second method is by adding a rewrite rule as shown below. You need to add this to your .htaccess file.

For example, a URL like,

Will redirect to

The redirect rule for .htaccess file is as follows.

RewriteRule ^[0-9]+/[0-9]+/(.*)$$1 [NC,L,R]

The second method is useful when you are changing the URL structure for existing site with many posts. First, you need to change the permalink and you need to add the following in the .htaccess file. This will avoid any 404 errors for the links you have added in other posts or websites.

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$$4

For more information, refer

(newkannada) #2

after adding this line links is working properly, thanku for that. but wp-admin not opening
can you please help me to fix this

(Annmary) #3

You could use a redirect in your server/site configuration, for example a RedirectMatch in your .htaccess:

RedirectMatch permanent ^/\d\d\d\d/\d+/\d+/(.*) /$1