WordPress permalinks setting allows bloggers to customize the structure of URL to beautiful URL which is more likely to be search engine optimized, and improve the aesthetics, usability, and forward-compatibility of the links. Within WordPress’s Permalinks setting, WordPress presents a few common permalinks structure, of which at least two are date-based.

The data-based permalinks have the following URL structure, for example:

Day and name: http://www.mydigitallife.net/2011/04/20/sample-post/
Month and name: http://www.mydigitallife.net/2011/04/sample-post/

The date in URL unnecessary adds to the length of URL. If you decide to strike off and remove the /yyyy/mm/dd or /yyyy/mm from the URL structure of the WordPress permalinks, here’s the tutorial on how to change the permalinks structure of WordPress URLs with proper redirect in order to avoid 404 page not found error and minimize potential lose of traffic and Google’s PageRank.

With the removal of data entry in the URL, the new URL structure of WordPress permalinks will become the below format:

http://www.mydigitallife.net/sample-post/

  1. Firstly, change the permalinks configuration to avoid infinite redirection loop (where Apache web server will redirect to new URL but WordPress redirects back to old URL). To do so, login to WordPress Dashboard, and go to Settings -> Permalinks tab.

    Select Custom Structure and enter /%postname%/ into the field behind it.

    WordPress Permalink Settings

    Click Save Changes to make the change effective.

  2. FTP or SSH into the web server which hosts the WordPress installation, and go to the directory of which the .htaccess file is located for the site.

    Alternatively, you can download the .htaccess to edit locally, and then re-upload the file once saved.

  3. Edit the .htaccess with vi other other editor.
  4. To use mod_rewrite to redirect from old URL structure to new URL structure which has no date in between, add in the following lines of code ahead of WordPress added block in .htaccess:

    For existing permalinks with /%year%/%monthnum%/%day%/%postname%/:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ /$4 [R=301,NC,L]

    For existing permalinks with /%year%/%monthnum%/%postname%/:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^([0-9]+)/([0-9]+)/(.*)$ /$3 [R=301,NC,L]

    Of course, it’s possible to merge the rewrite rule above to WordPress’ rewrite rules, just as shown in figure below.

    Redirect WordPress URL Structure to Remove Date

    To use mod_alias to redirect from old URL structure to new URL structure without date, add in the following line of code to the top of .htaccess:

    For existing permalinks with /%year%/%monthnum%/%day%/%postname%/:

    RedirectMatch permanent ^/[0-9]{4}/[0-9]{2}/[0-9]{2}/([a-z0-9\-/]+) http://www.mydigitallife.net/$1

    For existing permalinks with /%year%/%monthnum%/%postname%/:

    RedirectMatch permanent ^/[0-9]{4}/[0-9]{2}/([a-z0-9\-/]+) http://www.mydigitallife.net/$1

  5. Save the .htaccess.
  6. Try to click or enter a few links with old URL structure to test the redirection actually works.

Optionally, you may want to utilize MySQL replace function to replace the links with old permalink structure in posts, pages and comments to new URLs directly in database, much like what is been done when moving WordPress to new domain or location. Useful when you have thousands of articles which make manual changing impossible.