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
43
votes
8 answers

Is there an easy way to populate SlugField from CharField?

class Foo(models.Model): title = models.CharField(max_length=20) slug = models.SlugField() Is there a built-in way to get the slug field to autopopulate based on the title? Perhaps in the Admin and outside of the Admin.
ashchristopher
  • 25,143
  • 18
  • 48
  • 49
42
votes
12 answers

Can an "SEO Friendly" url contain a unique ID?

I'd like to start using "SEO Friendly Urls" but the notion of generating and looking up large, unique text "ids" seems to be a significant performance challenge relative to simply looking up by an integer. Now, I know this isn't as "human friendly",…
James White
  • 2,062
  • 2
  • 24
  • 36
39
votes
3 answers

How can I create a friendly URL in ASP.NET MVC?

How do I generate friendly URLs within the ASP.NET MVC Framework? For example, we've got a URL that looks like this: http://site/catalogue/BrowseByStyleLevel/1 The 1 is Id of the study level (Higher in this case) to browse, but I'l like to reformat…
Kieron
  • 26,748
  • 16
  • 78
  • 122
38
votes
3 answers

Convert non-ASCII characters (umlauts, accents...) to their closest ASCII equivalent (for slug creation)

I am looking for way in JavaScript to convert non-ASCII characters in a string to their closest equivalent, similarly to what the PHP iconv function does. For instance if the input string is Rånades på Skyttis i Ö-vik, it should be converted to…
Max
  • 12,794
  • 30
  • 90
  • 142
37
votes
13 answers

django.db.utils.IntegrityError: UNIQUE constraint failed: rango_category__new.slug

I'm learning Django from Tango with Django but I keep getting this error when I type: python manage.py makemigrations rango python manage.py migrate This is the output: django.db.utils.IntegrityError: UNIQUE constraint failed:…
ArrowsX
  • 505
  • 1
  • 4
  • 9
34
votes
13 answers

How to create a unique slug in Django

I am trying to create a unique slug in Django so that I can access a post via a url like this: http://www.example.com/buy-a-new-bike_Boston-MA-02111_2 The relevant models: class ZipCode(models.Model): zipcode = models.CharField(max_length=5) …
mitchf
  • 3,697
  • 4
  • 26
  • 29
28
votes
2 answers

URL Friendly Username in PHP?

On my PHP site, currently users login with an email address and a password. I would like to add a username as well, this username they g\set will be unique and they cannot change it. I am wondering how I can make this name have no spaces in it and…
JasonDavis
  • 48,204
  • 100
  • 318
  • 537
24
votes
10 answers

Convert string into slug with single-hyphen delimiters only

I would like to sanitize a string in to a URL so this is what I basically need: Everything must be removed except alphanumeric characters and spaces and dashed. Spaces should be converter into dashes. Eg. This, is the URL! must…
Atif
  • 10,623
  • 20
  • 63
  • 96
24
votes
1 answer

Wordpress: How to get the tag's slug on the tag page

I'm on the tag.php page. How can I get its slug? single_tag_title() gets the title just fine, but the slug?
podcastfan88
  • 970
  • 2
  • 13
  • 28
22
votes
8 answers

Generate SEO friendly URLs (slugs)

Definition From Wikipedia: A slug is the part of a URL which identifies a page using human-readable keywords. To make the URL easier for users to type, special characters are often removed or replaced as well. For instance, accented characters…
GG.
  • 21,083
  • 14
  • 84
  • 130
19
votes
4 answers

Should I create a slug on the fly or store in DB?

A slug is part of a URL that describes or titles a page and is usually keyword rich for that page improving SEO. e.g. In this URL PHP/JS - Create thumbnails on the fly or store as files that last section…
Guy
  • 65,082
  • 97
  • 254
  • 325
17
votes
12 answers

How can I create a SEO friendly dash-delimited url from a string?

Take a string such as: In C#: How do I add "Quotes" around string in a comma delimited list of strings? and convert it to: in-c-how-do-i-add-quotes-around-string-in-a-comma-delimited-list-of-strings Requirements: Separate each word by a…
Shawn
  • 19,465
  • 20
  • 98
  • 152
17
votes
4 answers

How to get attribute name instead of slug in variation?

I need to get attribute from woocommerce product variation. $terms = get_post_meta($value['variation_id'], 'attribute_pa_color', true); This code is giving me an attribute slug instead of name. How can I get attribute name? Thank you so much in…
Pupik
  • 391
  • 1
  • 2
  • 13
17
votes
6 answers

ID + Slug name in URL in Rails (like in StackOverflow)

I'm trying to achieve URLs like this in Rails: http://localhost/posts/1234/post-slug-name with both ID and slug name instead of either http://localhost/posts/1234 or http://localhost/posts/post-slug-name (right now I have just slug name in URL,…
Vitaly
  • 2,567
  • 5
  • 29
  • 34
16
votes
1 answer

How to Set POST permalink/slug in wordpress using wp_insert_post

I m writing simple script using wp_insert_post() to post article in blog. but one problem here, I want to make Title and slug of an URL different. How to achieve this? for example: Title: How to make your diet success Slug:…
Andy
  • 161
  • 1
  • 1
  • 3
1
2
3
84 85