Cleaning up Movable Type 4 URLs
Generally Movable Type 4 has nice URLs. However this is not the case for trackbacks and tag-clouds. This article describes how you clean them up, step by step using htaccess and mod_rewrite. I will not explain either htaccess or mod_rewrite but rather assume that you are familiar with them. If you are not, google them.
By default, the URLs look like this:
Trackback: http://bivald.com/cgi-bin/movabletype/mt-tb.cgi/<entry id>
Tag cloud: http://bivald.com/cgi-bin/movabletype/mt-search.cgi?tag=<tag>&blog_id=<blog id>
This is not beautiful. The idea of this article is to transform them into this:
Trackback: http://bivald.com/lessons-learned/trackback/13/
Tag cloud: http://bivald.com/lessons-learned/tag/<blog id>/<tag>
Getting started: HT Access and mod_rewrite
If you haven't got one already, create a .htaccess file in the parent folder of movable type. That is, if movable type is in:
> http://bivald.com/lessons-learned/ (public_html/lessons-learned)
The .htaccess should go into http://bivald.com/ (public_html/). If you are unfamiliar with htacces google it. Place the following two lines in it:
Make sure you copy them as three lines, starting with RewriteEngine, RewriteRule and RewriteRule. These lines assume two things, that your base url for movable type is lessons-learned and that your CGI files are in cgi-bin/movabletype. The first line enables mod_rewrite, google it if you aren't familiar with it, the two latter tells Apache to forward matches on URL lessons-learned/trackback and lessons-learned/tag to the matching .cgi-files.
What it does is to invisible convert lessons-learned/trackback/<entry-id> to cgi-bin/movabletype/mt-tb.cgi/<entry-id>
Save your file, and test it by going to:
http://www.yourdomain/your-mt/trackback/1 (replace 1 with a existing entry id). If you get a 500 Interal Server Error, you probably haven't got access to mod_rewrite. You should get the same page you would get for:
http://www.yourdomain/cgi-bin/movabletype/mt-tb.cgi/1
Getting Movable Type to print the new urls in templates.
We've now done half the work. The new URLs work, but if Movable Type doesn't print them they are of no use. Log in on Movable Type and choose Design -> Templates.
Open the Trackback template (Click "Template Modules" then "TrackBacks")
Replace "<$MTEntryTrackbackLink$>" with "http://bivald.com/lessons-learned/trackback/<$MTEntryID$>"
Edit template "Tags", change: "<$MTTagSearchLink$>&IncludeBlogs=<$MTBlogID$>" to "http://www.bivald.com/lessons-learned/tags/<$MTBlogID$>/<$MTTagName$>".
Then edit template "Sidebar - X Column Layout" (which ever you use), change: "<$MTTagSearchLink$>&IncludeBlogs=<$MTBlogID$>" to "http://www.bivald.com/lessons-learned/tags/<$MTBlogID$>/<$MTTagName$>".
Then republish your site. All in all, your trackback/tag links should be cleaner. Those a little more high-tech might want to edit lib/MT/Template/ContextHandlers.pm (and the corresponding functions) to make sure MT reports the correct URLs from the start, not just in the templates. But we'll save that for a rainy day..
By default, the URLs look like this:
Trackback: http://bivald.com/cgi-bin/movabletype/mt-tb.cgi/<entry id>
Tag cloud: http://bivald.com/cgi-bin/movabletype/mt-search.cgi?tag=<tag>&blog_id=<blog id>
This is not beautiful. The idea of this article is to transform them into this:
Trackback: http://bivald.com/lessons-learned/trackback/13/
Tag cloud: http://bivald.com/lessons-learned/tag/<blog id>/<tag>
Getting started: HT Access and mod_rewrite
If you haven't got one already, create a .htaccess file in the parent folder of movable type. That is, if movable type is in:
> http://bivald.com/lessons-learned/ (public_html/lessons-learned)
The .htaccess should go into http://bivald.com/ (public_html/). If you are unfamiliar with htacces google it. Place the following two lines in it:
RewriteEngine on
RewriteRule ^lessons-learned/trackback/([0-9]+)[\/]?$ cgi-bin/movabletype/mt-tb.cgi/$1 [L]
RewriteRule ^lessons-learned/tag/([0-9]+)/(.*) cgi-bin/movabletype/mt-search.cgi?tag=$2&IncludeBlogs=$1 [L]
Make sure you copy them as three lines, starting with RewriteEngine, RewriteRule and RewriteRule. These lines assume two things, that your base url for movable type is lessons-learned and that your CGI files are in cgi-bin/movabletype. The first line enables mod_rewrite, google it if you aren't familiar with it, the two latter tells Apache to forward matches on URL lessons-learned/trackback and lessons-learned/tag to the matching .cgi-files.
What it does is to invisible convert lessons-learned/trackback/<entry-id> to cgi-bin/movabletype/mt-tb.cgi/<entry-id>
Save your file, and test it by going to:
http://www.yourdomain/your-mt/trackback/1 (replace 1 with a existing entry id). If you get a 500 Interal Server Error, you probably haven't got access to mod_rewrite. You should get the same page you would get for:
http://www.yourdomain/cgi-bin/movabletype/mt-tb.cgi/1
Getting Movable Type to print the new urls in templates.
We've now done half the work. The new URLs work, but if Movable Type doesn't print them they are of no use. Log in on Movable Type and choose Design -> Templates.
Open the Trackback template (Click "Template Modules" then "TrackBacks")
Replace "<$MTEntryTrackbackLink$>" with "http://bivald.com/lessons-learned/trackback/<$MTEntryID$>"
Edit template "Tags", change: "<$MTTagSearchLink$>&IncludeBlogs=<$MTBlogID$>" to "http://www.bivald.com/lessons-learned/tags/<$MTBlogID$>/<$MTTagName$>".
Then edit template "Sidebar - X Column Layout" (which ever you use), change: "<$MTTagSearchLink$>&IncludeBlogs=<$MTBlogID$>" to "http://www.bivald.com/lessons-learned/tags/<$MTBlogID$>/<$MTTagName$>".
Then republish your site. All in all, your trackback/tag links should be cleaner. Those a little more high-tech might want to edit lib/MT/Template/ContextHandlers.pm (and the corresponding functions) to make sure MT reports the correct URLs from the start, not just in the templates. But we'll save that for a rainy day..

Leave a comment