Turn Sentences into Slugs with JavaScript

This simple script converts a text string into a valid URL slug. It mixes jQuery with standard JavaScript, and can be easily adapted to pure JS. <!-- Example input element --> <input id="controlId" type="text" /> // Handles typing $(document).ready(function () { // If the Title is specified, avoid overwrite if ($('#controlId').val().length === 0) { $('#controlId').on('keypress', function () { $('#controlId').val(slugify($('#controlId').val().toLowerCase())); }); } }); // Replacements function slugify(text) { text = text.replace(/[^-a-zA-Z0-9,&\s]+/g, ''); text = text.replace(/-/g, '_'); text = text.replace(/\s/g, '-'); return text; } Note (2025): For modern projects you may also want to normalize accents (é → e), trim repeated separators, and prefer input event instead of keypress. This post keeps the original 2010 logic. ...

October 20, 2010 · 1 min · Andrea Azzola

Improve ASP.NET SEO by using System.Web.Routing

This page is specific to Microsoft Visual Studio 2008/.NET Framework 3.5 or higher. SEO and ASP.NET “As an Internet marketing strategy, SEO considers how search engines work and what people search for. Optimizing a website primarily involves editing its content and HTML indexing activities of search engines.” — wikipedia.org Search Engine Friendly URLs vs “Dirty” URLs Example: SEF URL: http://AndreaAzzola.com/seo-asp-net-routing RAW URL: http://AndreaAzzola.com/Post.aspx?id=cd171f7c-560d-4a62-8d65-16b87419a58c SEFs are better to write, remember, understand, and maintain. In the example above you can immediately understand what the resource is about, while the RAW version is difficult to read and almost impossible to remember. ...

January 18, 2010 · 3 min · Andrea Azzola