slug

How do you include a webpage title as part of a webpage URL?

What is a good complete Regex or some other process that would take "How do you change a title to be part of the url like Stackoverflow?" and turn it into "how-do-you-change-a-title-to-be-part-of-the-url-like-stackoverflow" that is used in the smart urls? The dev environment is I am using is Rails but if there are some other platform sp...

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 is: http://stackoverflow.com/questions/47427/why-do-some-websites-add-slugs-to-the-end-of-urls But the following URL works j...

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. ...

Where to store the complete url in a cms?

I'm creating a cms and have not yet settled on the matter of where to store the complete url for a given page in the structure. Every page have a slug (url friendly name of the page) and every page has a nullable (for top-level pages) parent and children. Where do I store the complete url (/first-page/sub-page) for a given page? Should...

Turn a string into a valid filename in Python

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 other characters like "_-.() ". What's the most elegant solution? The filename needs to be ...

Cleaning form data in Django

How can i clean and modify data from a form in django. I would like to define it on a per field basis for each model, much like using ModelForms. What I want to achieve is automatically remove leading and trailing spaces from defined fields, or turn a title (from one field) into a slug (which would be another field). ...

Pros and cons of using DB id in the URL?

For example: http://stackoverflow.com/questions/396164/exposing-database-ids-security-risk and http://stackoverflow.com/questions/396164/blah-blah loads the same question. (I guess this is DB id of Questions table? Is this standard in ASP.NET?) What are the pros and cons of using this type of scheme in your web app? ...

what's the 5 character alphanumeric id in reddit URL?

Whats the 7n5lu in the reddit URL http://www.reddit.com/r/reddit.com/comments/7n5lu/man_can_fly_if_you_watch_one_video_in_2 how is it generated? update: @Gerald, Thanks for the code. I initially thought this is some obfuscation of the id. But, it is just doing the conversion from integer to a more compact representation. I am thinkin...

Is it OK to include an ID inside the URL ?

Hello people. Well, my question is simple. Does the ID affect the position of a webpage on Google ? I have links like this http://example.com/news/title-slug/15/ and people say to me that I should remove the ID from the URL. And I belive that is not true. By my logic, you can't depend on the title's slug. I know it should work per...

In django, what is a "slug"?

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 URL:s. How and when is this slug-thing supposed to be used? (I have read it's definition in this glossary) ...

What is the best way to store a unique URL Slug?

Hi folks, I'm trying to generate some url 'slugs' for my website. It's based upon a single piece of user generated text. Now, i have made my own slug method, so i'm not after some code for that. What i'm wondering is where is the best place to determine if this slug is unique and then insert it because the slug field is a Unique Key I...

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 dash and remove all punctuation (taking into account not all words are separated b...

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 fetch records with the tag/category slug, so the URL would look like : http://stackoverflo...

What is the best way to clean a string for placement in a URL, like the question name on SO?

I'm looking to create a URL string like the one SO uses for the links to the questions. I am not looking at rewriting the url (mod_rewrite). I am looking at generating the link on the page. Example: The question name is: Is it better to use ob_get_contents() or $text .= ‘test’; The URL ends up being: http://stackoverflow.com/questio...

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 they're calling this method in Question model to get permalinks def get_absolute_url(self)...

Does the position of a slug in a URL matter?

FOR SEARCH ENGINE OPTIMIZATION PURPOSES, does the location of the slug within a URL matter? There's no doubt that you could code URL slugs to work properly in any order. I'm more interested to know if search engines place different weights to portions of the URL on the right-hand-side vs the left-hand-side For example, here the slug ap...

Good name for "URL-friendly title"?

I'm creating a dynamic website with articles. Each article has a title, like "How does one eat a dog and live with it?", but also something I'm now calling "URL Friendly Title", such as "eating-a-dog". I'm looking for a better word for "URL Friendly Title", because it's quite a mouthful. Wordpress calls them "Post Slug" but I dislike th...

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 http://stackoverflow.com/questions/103707/php-js-create-thumbnails-on-the-fly-or-store-as-files that last section "php-js-create-thumbnails-on-the-fly-or-store-as-files" is the slug. Currently I am storing th...

how to use 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 test >>> t=test(q="aa a a a", s="b b b b") >>> t.s 'b b b b' >>> t.save() >>> t.s 'b ...

str_replace

Hi folks! Current code only replace the spaces to dash (-) $url = str_replace(' ','-',$url); I want only letters, numbers and dash (-) allowed on the URL. Let me know the tricks. ...