Not a developer? Go to MovableType.com

Ask an Expert

How can I prettify tag and keyword search URLs?

Asked by Caio
Posted May 30, 2013, in Featured.

Back

1 Answer

Charlie Gorichanaz

Charlie Gorichanaz on October 28, 2013, 1:53 a.m. Reply

Hi Caio,

The default URL for a Movable Type text search looks like:

MT_DIR/mt-search.cgi?search=SEARCH_TEXT&IncludeBlogs=2&limit=20

The default URL for an MT tag search looks like:

MT_DIR/mt-search.cgi?IncludeBlogs=2&tag=TAG_NAME&limit=20

You could use URL rewriting to redirect from a simple URL to the complex one, hiding some of the MT internals in the process.

For example, if you’re using Apache web server, you could use a RewriteRule in an .htaccess file. You might make an index template in each blog such as this:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^tag/(.*)$ <$mt:CGIRelativeURL$><$mt:SearchScript$>?IncludeBlogs=<$mtBlogID$>&limit=20&tag=$1 [L,PT]
RewriteRule ^search/(.*)$ <$mt:CGIRelativeURL$><$mt:SearchScript$>?IncludeBlogs=<$mtBlogID$>&limit=20&search=$1 [L,PT]

Make the template publish to .htaccess, so that each blog in your system will get its own file with the correct blog ID in the InlcudeBlogs parameter.

Now you can conduct tag and text searches using URLs like:

yourdomain.com/blogname/tag/my+tag
yourdomain.com/blogname/search/my+search+phrase

Charlie Gorichanaz

Charlie joined Six Apart as a Japan based product manager for Movable Type in February 2014 after spending two years as a developer for 601am. Previously he was the web director of The Badger Herald while studying biochemistry at the University of Wisconsin-Madison.

Website: http://votecharlie.com/
Twitter: @CNG

Ask An Expert