Questions tagged [slug]

part of a URL that makes it more human readable or SEO-friendly, but without necessarily being required by the web server.

A slug is a part of a URL that makes it more human readable or SEO-friendly, but without necessarily being required by the web server. Slugs can be generated from a page title and are typically the last part of the url.

Example:

  • Page Title: c# - What's the difference between String and string? - Stack Overflow
  • Slug: whats-the-difference-between-string-and-string

The full URL including the slug is https://stackoverflow.com/questions/7074/whats-the-difference-between-string-and-string. Note that punctuation in the url is typically removed.

1272 questions
760
votes
14 answers

What is a "slug" in Django?

When I read Django code I often see in models what is called a "slug". I am not quite sure what this is, but I do know it has something to do with URLs. How and when is this slug-thing supposed to be used? I have read its definition below in this…
Jonas
  • 19,422
  • 10
  • 54
  • 67
428
votes
27 answers

Turn a string into a valid filename?

I have a string that I want to use as a filename, so I want to remove all characters that wouldn't be allowed in filenames, using Python. I'd rather be strict than otherwise, so let's say I want to retain only letters, digits, and a small set of…
Sophie Gage
  • 5,391
  • 5
  • 24
  • 25
284
votes
3 answers

Replace all characters that aren't letters and numbers with a hyphen

I am facing an issue with URLs, I want to be able to convert titles that could contain anything and have them stripped of all special characters so they only have letters and numbers and of course I would like to replace spaces with hyphens. How…
user115422
  • 4,662
  • 10
  • 26
  • 38
267
votes
21 answers

How does Stack Overflow generate its SEO-friendly URLs?

What is a good complete regular expression or some other process that would take the title: How do you change a title to be part of the URL like Stack Overflow? and turn it into…
wusher
  • 12,291
  • 22
  • 72
  • 95
259
votes
2 answers

What is the etymology of 'slug' in a URL?

Is "URL slug" a completely arbitrary word? Or does it stand for something? I used the word in a conversation with someone and when they asked me why it's called that I realized I didn't know. I know what it means of course. The Stack Overflow tag…
Matthew
  • 15,282
  • 27
  • 88
  • 123
251
votes
11 answers

How do I create a slug in Django?

I am trying to create a SlugField in Django. I created this simple model: from django.db import models class Test(models.Model): q = models.CharField(max_length=30) s = models.SlugField() I then do this: >>> from mysite.books.models import…
Johnd
  • 6,441
  • 9
  • 29
  • 22
219
votes
31 answers

PHP function to make slug (URL string)

I want to have a function to create slugs from Unicode strings, e.g. gen_slug('Andrés Cortez') should return andres-cortez. How should I do that?
Andres SK
  • 10,779
  • 25
  • 90
  • 152
206
votes
26 answers

How to convert a Title to a URL slug in jQuery?

I'm working on an app in CodeIgniter, and I'm trying to make a field on a form dynamically generate the URL slug. What I'd like to do is remove the punctuation, convert it to lowercase, and replace the spaces with hyphens. So for example, Shane's…
GSto
  • 41,512
  • 37
  • 133
  • 184
135
votes
12 answers

String slugification in Python

I am in search of the best way to "slugify" string what "slug" is, and my current solution is based on this recipe I have changed it a little bit to: s = 'String to slugify' slug = unicodedata.normalize('NFKD', s) slug = slug.encode('ascii',…
Zygimantas
  • 8,547
  • 7
  • 42
  • 54
115
votes
14 answers

Why do some websites add "Slugs" to the end of URLs?

Many websites, including this one, add what are apparently called slugs - descriptive but as far as I can tell useless bits of text - to the end of URLs. For example, the URL the site gives for this question…
David Webb
  • 190,537
  • 57
  • 313
  • 299
95
votes
5 answers

URL Slugify algorithm in C#?

So I have searched and browsed through the slug tag on SO and only found two compelling solution: Slugify and Character Transliteration in C# How to convert super- or subscript to normal text in C# Which are but partial solution to the problem. I…
chakrit
  • 61,017
  • 25
  • 133
  • 162
71
votes
12 answers

Best way to generate slugs (human-readable IDs) in Rails

You know, like myblog.com/posts/donald-e-knuth. Should I do this with the built in parameterize method? What about a plugin? I could imagine a plugin being nice for handling duplicate slugs, etc. Here are some popular Github plugins -- does anyone…
Tom Lehman
  • 85,973
  • 71
  • 200
  • 272
46
votes
4 answers

Java code/library for generating slugs (for use in pretty URLs)

Web frameworks such as Rails and Django has built-in support for "slugs" which are used to generate readable and SEO-friendly URLs: Slugs in Rails Slugs in Django A slug string typically contains only of the characters a-z, 0-9 and - and can hence…
knorv
  • 49,059
  • 74
  • 210
  • 294
45
votes
8 answers

How to make Django slugify work properly with Unicode strings?

What can I do to prevent slugify filter from stripping out non-ASCII alphanumeric characters? (I'm using Django 1.0.2) cnprog.com has Chinese characters in question URLs, so I looked in their code. They are not using slugify in templates, instead…
Imran
  • 87,203
  • 23
  • 98
  • 131
45
votes
3 answers

Why SlugField() in Django?

Django has models.SlugField() which helps us to create some cool looking urls. My question is why specifying it as a field suppose I have this model class Blog(models.Model): title = models.CharField() and if I want to add slug, I could just…
Ryu_hayabusa
  • 3,666
  • 2
  • 29
  • 32
1
2 3
84 85