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
7
votes
4 answers

Django slugified urls - how to handle collisions?

I'm currently working on a toy project in Django. Part of my app allows users to leave reviews. I'd like to take the title of the review and slugify it to create a url. So, if a user writes a review called "The best thing ever!", the url would be…
TM.
  • 108,298
  • 33
  • 122
  • 127
7
votes
1 answer

Slug Url Regex in Django

After reading a lot about proper use of a slug to create a detail view from a list of objects. However, I am still having problems getting it to work for me. I am displaying a list of objects in my template like: {% for thing in thing_list %} …
Nick B
  • 9,267
  • 17
  • 64
  • 105
7
votes
2 answers

django auto slug in model forms like prepopulated-fields in django admin

is there a way to get the same results of using pre-populated fields in django's admin site for slug fields in a standard modelform
Llanilek
  • 3,386
  • 5
  • 39
  • 65
7
votes
1 answer

Friendly_id not creating slugs for old records

I just added the Friendly_id gem to my rails project looking to not use the database id and create a slug, but I can't seem to create slugs for old records. My model looks like this. class Mapping < ActiveRecord::Base extend FriendlyId …
rigelstpierre
  • 534
  • 1
  • 6
  • 22
7
votes
5 answers

Extract first URL Segment from full URL

How can the first URL segment be extracted from the full URL? The first URL segment should be cleaned to replace the - with a space . Full…
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
6
votes
3 answers

How to make Django create slug from unicode characters?

Django Unicode Slug how to ? class NewsModel(models.Model): title = models.CharField(max_length = 300) slug = models.CharField(max_length = 300) content = models.TextField() def save(self,*args, **kwargs): if self.slug is…
Ankhaa
  • 1,128
  • 2
  • 12
  • 17
6
votes
2 answers

wordpress: how to check if the slug contains a specific word?

I'm trying to use a conditional statement to check if either of two words (blog & news) appear in the slug. If one shows up I will display one menu, if the other then its corresponding menu shows.
Andy
  • 454
  • 2
  • 7
  • 22
6
votes
5 answers

parse URL with JavaScript or jQuery

Ok lets say I have a URL example.com/hello/world/20111020 (with or without the trailing slash). What I would like to do is strip from the url the domain example.com. and then break the hello world 20111020 into an array. But my other problem is.…
chris
  • 36,115
  • 52
  • 143
  • 252
6
votes
2 answers

Fetching records with slug instead of ID

I'm currently trying to find the best way (in term of usability and performance) when dealing with a situation like fetching records tagged with a specific tag, or category, or something like that. A good way (the way I wanted to do), would be to…
andyk
  • 10,019
  • 10
  • 36
  • 41
6
votes
2 answers

Symfony: generating slug url in my article url instead of news id

I would like to have an url like this one: www.mysite.com/my-super-blog-post Instead of this one: www.mysite.com/7 Where '7' is the id property of my News object. When I see at the Symfony documentation I think I need to use this line of…
zm455
  • 489
  • 11
  • 26
6
votes
4 answers

Laravel Route model binding (slug) only works for show method?

I have Article model and articles table in the database. Each article can be shown using Laravel's standard URI structure: www.example.com/articles/5 (where 5 is the article id). Each article has a slug field (slug column in the articles table), so…
PeraMika
  • 3,539
  • 9
  • 38
  • 63
6
votes
1 answer

DDD: where to generate url slug of an entity?

how do you deal with url slug generation in DDD? Inside constructor? But entity relying on other service is not good. Pass as constructor argument? I think slugs shouldnt be there because they are not business requirements. are they? or just having…
Jaime Sangcap
  • 2,515
  • 6
  • 27
  • 45
6
votes
2 answers

best way to escape and create a slug

Possible Duplicate: URL Friendly Username in PHP? im somehow confused in using proper functions to escape and create a slug i used this : $slug_title = mysql_real_escape_string()($mtitle); but someone told me not to use it and use…
Mac Taylor
  • 5,020
  • 14
  • 50
  • 73
6
votes
3 answers

How can I make URLs in Django similar to stackoverflow?

I'm creating a video site. I want my direct urls to a video to look like example.com/watch/this-is-a-slug-1 where 1 is the video id. I don't want the slug to matter though. example.com/watch/this-is-another-slug-1 should point to the same page. On…
user281773
6
votes
5 answers

Pretty (dated) RESTful URLs in Rails

I'd like my website to have URLs looking like this: example.com/2010/02/my-first-post I have my Post model with slug field ('my-first-post') and published_on field (from which we will deduct the year and month parts in the url). I want my Post…
Paweł Gościcki
  • 9,066
  • 5
  • 70
  • 81