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:
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.
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:
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:
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:
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:
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).
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.
(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 http://learningmovabletype.com/ . Thanks!
If you would like to send a trackback
please use the following URL: http://learningmovabletype.com/cgi-bin/mt32/mt-tb.cgi/189
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
Comments are now closed for this entry.