RT Cunningham

Changing My Permalinks – Why are they called Permalinks anyway?

Permalinks are supposed to be permanent links. In my experience, they aren’t any more permanent that the default query links used by content management systems.

According to Wikipedia, most modern blogging and content management software systems support these types of links. The WordPress self-hosted software offers five preset options along with a custom option. The first option is the default query link option.

Changing Permalinks

When I first set up this website, I used permalinks that ended in a single slash. That’s fine for database queries. When caching pages, subdirectories have to be created to handle the slash characters.

When I decided to go completely static, I switched the trailing slash for the “.html” file extension. That was a mistake. I should have simply dropped the trailing slash and that’s exactly what I did today.

Categories, tags (and custom taxonomies) and author pages still have a slash separating the base name from the rest. I use this function to replace the slash with a dash:

add_action('init', 'change_taxonomy_permalinks', 1);
function change_taxonomy_permalinks() {
  global $wp_rewrite;
  $wp_rewrite->author_structure = '/' . $wp_rewrite->author_base . '-%author%';
  add_permastruct('category', 'category-%category%');
  add_permastruct('post_tag', 'tag-%post_tag%');

As you can probably tell, changing the slash to a dash for the author taxonomy is a little more involved than the others.

So, why did I Change My Permalinks?

Adding “.html” to my permalinks was a rewrite hack. Some things didn’t work right and I just put up with it. After all, I could make the necessary changes while my script read the pages from the database and then saved them to text files.

I don’t like fixing things after the fact. It’s just one more thing that can get screwed up. I use WordPress on my laptop just like it’s used online. If reading and saving is all I have to worry about, I don’t get any unnecessary headaches.

There’s one more reason. The search bots keep looking for the URLs with and without trailing slashes or “.html” extensions. I now have server rewrites in place to prevent the 404 errors they cause.

I have to leave one page with the “.html” extension and there isn’t a way around it. It’s the index page. It has to have some kind of extension and “.html” is just as good as any.

Server Errors

When I changed everything and published this article, I had server issues. To make pages without file name extensions readable as html, I had to change the default mime type to text/html. For whatever reason, the CSS mime type was being transmitted that way as well when it should have been text/css. The index page wasn’t being read correctly either.

I won’t go into the details of fixing things. Those server issues may never crop up for anyone else. They stole two hours of my time and that’s about it.

March 14, 2018
Web Development

You May Also Like: