WordPress Permalink Options
As I read 2 posts on the Simple Thoughts blog about permalinks in WordPress I realized I wanted my permalinks to be ‘cleaner’. When I set up WordPress I set my permalinks to use dates in the URI:
http://dogberrypatch.com/archives/random-photo-plugin/
But with the revised ‘cleaner’ structure that same link is now found at:
http://dogberrypatch.com/archives/random-photo-plugin/
In the first article, Why I discourage embedding date in URL’s (including WordPress Permalinks and also other CMS), the author gives 5 reasons why you should not embed the date in the URI. The most convincing one for me was #1, the date is already part of the post text – it is redundant in the URI. It really just makes it longer.
The drawback to not having the date as part of the URI is that it is possible to end up with 2 posts with identical names. Since I hope never to have 2 children with the same name, I can also hope to never name 2 of my posts with the same name. Maybe someday there will be a routine built into WP to check for this.
The second article is titled WordPress Tip on Permalink Options and dealt with more of the nitty gritty. After I read the responses and felt like I had a handle on it – I decided to do nothing. But then morning came and bravery crept in and I said what the heck.
Being a noob with php, apache, etc, I was reluctant to do anything that might ‘break’ my site. But I backed up everything (including a spare copy of .htaccess) and then changed my permalink template to /archives/%postname%/ and hit the ‘Update PermaLink Structure’ button.
It worked!!
Then I realized all the links out in the wild world to my site were now probably broken. And even though I like my 404 message – I prefer people not get it.
So, since I was being brave, I opened that back up copy of .htaccess and compared it with the new one. I think I figured out how all the regular expressions were doing what they were supposed to do enough to try something bold. I copied the lines that started with ^([0-9]{4}) and replaced the pattern at the end:
index.php?year=$1&monthnum=$2&day=$3&name=$4
with just:
index.php/archives/?name=$4
In other words I replaced "year=$1&monthnum=$2&day=$3&" with "\archives" in those lines.
I pasted the modified lines of the old .htaccess file to the new one that was created by WordPress and a quick test shows it worked – now the old links on my pingbacks, tracklogs, etc still should work. I emphasize ‘should’ since I really have no clue about this stuff since I am an insurance agent and not a professional propeller head. ;)







Seems that WordPress has overwritten my changes to .htaccess
I did find .htaccess tips and tricks and more .htaccess tips and tricks along with .htaccess Tutorial which gives a pretty good tutorial on what you can do with .htaccess
Hopefully I will figure out if I can just move the lines to another section of the file?
Comment by Gary Paulson — May 10, 2005 @ 9:00 pm
Well, attempt 2 to get the old links to work. I put the following right above the
# WORDPRESSline in .htaccess (All the Rewrite rules between the<Ifs...>s are single lines)<IfModule mod_rewrite.c>RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?name=$4&feed=$5 [QSA,L]RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?name=$4&feed=$5 [QSA,L]RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/page/?([0-9]{1,})/?$ /index.php?name=$4&paged=$5 [QSA,L]RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/?([0-9]+)?/?$ /index.php?name=$4&page=$5 [QSA,L]RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/trackback/?$ /index.php?name=$4&tb=1 [QSA,L]</IfModule>Comment by Gary Paulson — May 10, 2005 @ 9:54 pm
Good to know you found it useful. The old links should still work without any moidifcations on your part, if it was like index.php?p=123 which is the default link system used by wordpress.
Personally I use a modified version of wp_old_link_redirect plugin, so old links are redirected to my new ones with 301 (Permanent Redirect). This preserves Google juice to my site :)
Comment by Angsuman Chakraborty — May 10, 2005 @ 11:10 pm
My original links were the new type permalinks using the date /year/month/day/ format. So when an old link came in it looked like this:
http://dogberrypatch.com/archives/random-photo-plugin/
But with the revised structure that link is now found at: http://dogberrypatch.com/archives/random-photo-plugin/
So, when something came in to the old address it was 404ing. Will have to look at the redirect plugin. But I don’t have that much on my site yet so probably not as big a deal as it was for you.
Comment by Gary Paulson — May 11, 2005 @ 12:19 am
I guess then it is different. Either .htaccess (which I personally avoid as it can very easily break things) or modifying the plugin to re-direct old link constructs to new ones.
I checked that WordPress 1.5 actually handles duplicate posts correctly. No issue there at all. I thought I clarified it somewhere in either of the two posts. I will check again.
Comment by Angsuman Chakraborty — May 11, 2005 @ 3:18 am
Let me know if the code I sent via email works for you.
Comment by Angsuman Chakraborty — May 12, 2005 @ 9:31 pm
I just made another mod to my .htaccess file and figured I would put it here so if I need it again later I will ahve it.
Inside the
<IfModule>statement mentioned in comment 2 above I addedRewriteRule ^archives/([0-9]+)/?$ /?p=$1 [QSA,L]This rewrite rule fixes trackbacks and pings when you accidentally save the post without a name and so it names it by the post number. This rewrite changes just removes the permalink stuff and tells it to go to that page.
I have also added the following – and does not look like I wrote it down anywere so will ‘save’ it here to.
RewriteRule ^wordpress-making-it-mine/wordpress-plugins /archives/wordpress-plugins-installed [QSA,L]RewriteRule ^wordpress-making-it-mine/wordpress-ideas /archives/wordpress-ideas [QSA,L]RewriteRule ^wordpress-making-it-mine/wordpress-templates /archives/wordpress-templates [QSA,L]RewriteRule ^wordpress-making-it-mine/wordpress-hacks /archives/wordpress-hacks [QSA,L]RewriteRule ^wordpress-making-it-mine /archives/wordpress-making-it-mine [QSA,L]These rules were due to me moving some static pages to regular pages.
Comment by Gary Paulson — May 25, 2005 @ 1:44 pm