March 01, 2004

File Names and URLs

The default entry URL file name structure for Movable Type 2.6 looks something like this:

This structure puts all of the files into one archive directory and assigns each of them a number corresponding to the number of entries you have entered so far in your weblog.

What if you would prefer to have the URLs for your entries include the actual name of the entry and maybe even the category they are in? Something like this:


1. Using the entry title instead of the entry number. On the left hand side of your weblog edit window, click on "weblog config" navigation element.

In the weblog config window, click on "Archiving".

In the Archive File Template window for Individual Entry Archive enter the following:

<$MTEntryTitle dirify="1"$>.html

Like this...

If you use entry titles in your URLs, and your entry title is somewhat long, you can end up with a pretty long URL. To keep your URLs at a reasonable length you can use the trim_to option.

<$MTEntryTitle dirify="1" trim_to="20"$>.html

will keep the entry name in the URL to 20 characters or less.

Alternatively, you could use the following:

which will spell out only the first 15 letters. <$MTEntryBasename$> is an MT tag that generates a unique string for the entry with the first 15 letters of the title, and dirifies (connects with an underscore and removes odd characters) them as well. If there are more than one entry with the same first 15 letters, MTEntryBasename will add a number at the end, to uniquely identify each particular entry.

2. Adding a category directory to the URL. If you want to add a category directory but keep the file numbers enter this code in the Archive File Template window for Individual Entry Archive:

<$MTEntryCategory dirify="1"$>/<$MTEntryID pad="1"$>.html

Note: be sure to use the proper file extension. If you are using .html on your site, use .html here. If you are using .php on your site, use .php here.

If you want to lose the file numbers and combine both the category directory and the title (the first 15 letters of the title) in the URL, enter this code:

<$MTEntryCategory dirify="1"$>/<$MTEntryBasename$>.html

I like to keep both the entry number and the entire entry title in the URL - it helps me find the files if they are in chronological order. In this case one would use:

<$MTEntryID pad="1"$><$MTEntryTitle dirify="1"$>.html

3. Using a date file structure. The default file structure for MT version 3.x is the format of year/month/entry_name.html. If you are using an older version of MT, or have upgraded to MT3 from an earlier version, and would like to change your file name structure to the default for MT3, enter this code in the Individual Archive File Template window:

<$MTEntryDate format="%Y/%m"$>/<$MTEntryBasename$>.html

4. Changing the file name for categories. The default URL file name for categories looks something like this:

If you would like it to look more like this

enter the following code in the Category Archive Archive File Template Window (underneath the other Archive File Template windows).

<$MTArchiveCategory dirify="1"$>/index.html

5. Finishing touches. First, save and rebuild. Second, if you already have a site up and are changing the file naming structure after you already have entries, the existing file entries with their old URLs will not go away on their own. You will need to FTP into your file directory and remove them if you want them off your server. If you want to keep the files with the old file names on your server (if other sites link to them you might want to do this) you can use a page editing tool (like BBEdit) to add a meta refresh tag to the page's HTML header, redirecting the viewer to the new URL.

<meta http-equiv="refresh" content="3;url=">

(Replace the URL shown above with your page's new URL.)

If your site pages have PHP extensions you can alternatively use a PHP redirect. See this tutorial for directions.


MT Manual on Archive File Templates

Has this tutorial been helpful? Please consider linking to Learning Movable Type at . Thanks!

Posted by Elise Bauer on March 01, 2004 to General Tips and Tricks
Comments(19) | Email to a friend | Printer-friendly version


If you would like to send a trackback
please use the following URL:

» Movable Type URL tweaks from Inchoate
I've been having "URL envy" for some blogs where the title of the entry appears in some form in the URL. So instead of /archives/002996.html it's /archives/that_blog_about_foo.html. Not only is the URL now descriptive, it's easy for me to remember,......[read more]

Tracked: August 1, 2004 09:35 AM


About point #5. If you delete those posts and others have linked to them or trackbacked to them then their links will be dead. It is probably best to leave those files on your server as they will still have links to your index page and html files take up very little space on a server.

Point well taken. It all depends on the file. Half the time I delete the file completely, the rest of the time I leave it up there, often with a meta refresh tag to send it to the new URL.

I found this entry from Mark Pilgrim to be extremely helpful when trying to figure out how to archive my entries. It uses the MTifEmpty plugin and the keywords MT feature to create file names. very handy.

hi. thank u for those precious tips.

If i would like to omit the Archives folders out of my hierarchy, do i just omit it in the weblog config ?

when u change the path like u do, is the PERMALINK link stay the same ? is it still the way to call my entries ?

And even more complicated... when implementing Categories and Sub - and maybe SubSubCat - , SUBCATEGORIES plugin, do the permalink in that case still go to the entry? if not, do u know how to link entries to such a complicated path ?

Good stuff, clearly explained. For the conversion to file names based on the post title, if you are like me, you may get longwinded writing titles and end up creating ridiculously long URLs. I add the trimto option to the file name to cut it off at 20 chars (sometimes looks odd, but consistent:

<$MTArchiveDate format="%Y/%m/%d"$>/<$MTEntryTitle dirify="1" trim_to="20"$>.html

And ditto for using Mark Pilgrim's Cruft Free email listed above- I use this approach as well to create individual archive names based on the date and the keywords entered; if no keyword, it uses the convention above:

<$MTArchiveDate format="%Y/%m/%d"$>/<MTIfEmpty var="EntryKeywords"><$MTEntryTitle dirify="1" trim_to="20"$></MTIfEmpty><MTIfNotEmpty var="EntryKeywords"><$MTEntryKeywords dirify="1"$></MTIfNotEmpty>.html


I also leave the old archives named under other rules, they really do not take up that much space, and I have about 400 posts per year.

Alan, Thanks a bunch for the tip on trim_to. I've included it above.

Patricia - Thanks for the keyword and MTifEmpty plugin tip, good to know about.

All - Please please direct support questions to the MT Support Forums at I'm really not an MT expert at all, I'm just writing up what I've learned and I don't really have time in addition to troubleshoot other people's MT issues. I have a challenging time enough with my own! The good people at the MT Support Forums are incredibly helpful and knowledgeable. Thanks for your understanding on this. Of course, if something I suggest here on Learning Movable Type doesn't work, AND you are using the MT default templates and styles then of course I want to hear about it. Thanks!

I'd just like to add that I found this information extremely helpful. Thanks a ton.

I was looking for another tip (which I found!) when I found this one. I had assumed this was an expert-level tip. Well, what do you know! This is easy. Elise, you make us all look so good.

Stopped by to say hi. I remember when you added this, I was pulling my hair out trying to get the code for
I felt I was from another planet asking how to do it, when it seemed such a normal way of doing things. Your tutorial helped me get it. Moved on to other things in MT now, like redoing templates and stylesheets, php etc, but thanks for the help. I keep an rss feed of your site handy on mine for emergencies :-)

Hi Elise - Under item #4 you list the category URL code as:

<$MTEntryDate format="%Y/%m"$>/<$MTEntryTitle dirify="1"$>.html

I tried this and I received an error during rebuilding. After some searching I found the string that worked properly, and achieved the /category/index.html URL:

<$MTArchiveCategory dirify="1"$>/index.html

I wonder if others have found this not working right for them. The new string has fixed things for me.

Note, if anyone can tell me how to "archive" the category page (by month or whatever) that would be brilliant. The reason is that if you add enough content to a category, that page will be HUGE after a time, and too large to load (esp. if you have images). For example, can you have the most recent entries on a /category/index.html,
THEN have /category/YEARmm.html? This would require some kind of easy navigation module on the category page so you can get to the other pages.

Now that I'm getting so into MT I'm finding it hugely adaptable. I bet there's a way to do what I'm asking for, but it's just a bit beyond my understanding right now.

Thanks as always for this great resource!


Sorry to be a comment hog today. I just discovered my answer on category archives -

Another big thanks to Elise!


Hi Kino, Thanks for pointing out that error! I have no idea how that happened. It was clearly not the right string. I've replaced it with the correct one thanks to you.

Elise, great site. I've been looking for a blog like this. I am going to change my archive file names over to the actual names from the numbers using your code above. But I have one question. After I change it over and rebuild, will all the old number file names be erased or will they just duplicate? Being that some people have linked to my posts, they links would be broken if they are replaced and not duplicated. Thanks for the help.

Hi Sean, the old files will remain on your server unless you use an FTP program to delete them. But they will not be updated if you update your site. What I do in cases like this is add a meta refresh tag (as mentioned in the tutorial) to the indiv entry archive template with the old URL format. I have the meta refresh point to the new URL format. I save, rebuild, and then change the blog's URL format, remove the refresh tag from the indiv entry archive template, save, and rebuild again. This way when someone goes to an old file they will be redirected to the new one.

Thanks again Elise.

Ok, one more question. (Looks like I'm the comment hog today) Now, if I do exactly what you say above and add this

meta http-equiv="refresh" content="3;url="

to the IAE template, do I need to manually change each tag for each page? (I have about 400 pages) Or is there a TAG that is supposed to go in there that points to the new page? Am I confusing you? Basically, I need to put the refresh code in each of my old pages with the 0000001.html extension to point towards 000001_new_file_name.php.

Hi Sean, try this...

<meta http-equiv="refresh" content="3;url=<$MTBlogArchiveURL$><$MTEntryID pad="1"$><$MTEntryTitle dirify="1"$>.php">


Thanks again. I finally got a chance to finish everything tonight. It's all working.

Instead of drifty get the "drafty" plugin.

Comments are now closed for this entry.

Email to a friend

Email this article to:

Your email address:

Message (optional):