Changing WordPress Permalink While Still Maintaining Accessibility

Posted by on Tue, April 29, 2008

▼ A d v e r t i s e m e n t

I’ve been wanting to change my permalink structure for a while now but I was afraid to lose pageranks on some of my pages. However since I realize that I have been penalized and none of my page have ranks anymore, I’ll just change it.

But there is another issue that you should be worried about if you change your permalink: incoming links from other blogs / sites. They will be rendered unusable.

I used to use /%year%/%monthnum%/%day%/%postname%/ (Day and name) as my setting. After a while it looks ugly and long with so many numbers. http://www.romantika.name/v2/innotek-virtualbox/ looks much nicer than http://www.romantika.name/v2/2008/04/26/innotek-virtualbox/.

The issue here is that we want the latter to still work.

There is a simple remedy to this problem. You can edit .htaccess file to add some rules to rewrite your old permalink structure to the new one. The rule I will explain below will redirect the page to the new permalink.

The default .htaccess looks like this:

1
2
3
4
5
6
7
8
9
# BEGIN WordPress
<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</ifmodule>
# END WordPress



You should NEVER change anything what is inside the # BEGIN WordPress and # END WordPress tags as they will get overwritten by WordPress (if file permission allows). Put your new rules above those.

The following will explain on how to achieve custom /%postname%/ permalink.

My addition looks like this (added to top of the .htaccess file):

1
2
3
4
5
<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteBase /v2/
RewriteRule ^[1-2][0-9][0-9][0-9]/[0-1][0-9]/[0-3][0-9]/(.*)/ http://www.romantika.name/v2/$1/ [R,NE,L]
</ifmodule>

Careful about the last portion of the RewriteRule line. Put your own site there. For example if your site is http://www.yoursite.com/ you should change it to http://www.yoursite.com/$1/

RewriteBase should be changed if you have a subdirectory, for example http://www.yoursite.com/blog/ so remember to also change the RewriteRule line to http://www.yoursite.com/blog/$1/

For those who have been using /%year%/%monthnum%/%postname%/ (Month and name) you can use this:

RewriteRule ^[1-2][0-9][0-9][0-9]/[0-1][0-9]/(.*)/ http://www.yoursite.com/$1/ [R,NE,L]

For the numeric structure /archives/%post_id%

RewriteRule ^archives/(.*) http://www.yoursite.com/?p=$1 [R,NE,L]

and WordPress will do its magic to redirect to the new permalink.

Ask below if you need a special conversion, and I’ll try to help if the rewrite is possible.

Related Posts with Thumbnails

Tags:

Facebook Comment

WARNING & REMINDER: Comments are moderated and there is no exception. Comments unrelated to the post, too short, using phoney emails or funny names, will be marked as spam. Foul languages are filtered as spam. Your email will never be displayed on this site. If you would like to receive replies, use a valid email address and check the subscription box below.
 
  • I, too, don’t like the /%year%/%monthnum%/%day%/%postname%/ format. But many well-known bloggers seem to be fine with it. Perhaps they find it useful to have the posting date embedded in the permalink.