slug

Canonical links and 301 Redirect if URL doesn't match slug

这一生的挚爱 提交于 2019-12-03 12:45:39
问题 I am trying to implement a URL scheme similar to stack overflow's in django/python. E.g. the pk is stored in the URL along with a slug of the title so for this question (id #4787731) the URL is https://stackoverflow.com/questions/4787731/canonical-links-and-301-redirect-if-url-doesnt-match-slug If I later change the title (or just put in some random crud into the url) then the site will still know which question I am after (by the ID) and will 301 redirect to the correct URL - e.g. try. https

How to Set POST permalink/slug in wordpress using wp_insert_post

匆匆过客 提交于 2019-12-03 12:34:23
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: 7-ways-to-make-succes-Diet post_title sets the title, and post_name sets the slug. So: // Create post object $my_post = array( 'post_title' => 'How to make your diet success', 'post_name' => '7-ways-to-make-succes-Diet', 'post_content' => 'my content', 'post_status' => 'publish', 'post_author' => 1, 'post_category' => array(8,39) ); // Insert the post into the database wp

Best way to create SEO friendly URI string

耗尽温柔 提交于 2019-12-03 12:20:11
The method should allows only " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- " chars in URI strings. What is the best way to make nice SEO URI string? This is what the general consensus is: Lowercase the string. string = string.toLowerCase(); Normalize all characters and get rid of all diacritical marks (so that e.g. é, ö, à becomes e, o, a). string = Normalizer.normalize(string, Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); Replace all remaining non-alphanumeric characters by - and collapse when necessary. string = string.replaceAll("[^\\p{Alnum}]+", "-");

create URL slugs for chinese characters. Using PHP

假如想象 提交于 2019-12-03 08:51:09
My users sometimes use chinese characters for the title of their input. My slugs are in the format of /stories/:id-:name where an example could be /stories/1-i-love-php . How do I allow chinese characters? I have googled and found the japanese version of this answer over here . Don't quite understand Japanese, so I am asking about the chinese version. Thank you. i have tested in Bengali characters it may work. try this: at first the coded page (write code where in the page) have to convert into encoding type in UTF-8, then write code. code here: function to_slug($string, $separator = '-') {

Reduce Heroku Compiled Slug Size

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 07:17:53
I've just updated rails to v2.3.6 on my app under a bamboo-ree-1.8.7 stack and the compiled slug size has grown up to 40.5Mb! Previous to that last git push, the slug size was about 20Mb and was using rails v2.3.5. Is it because my slug has both of rails versions installed? Probably I'm missing something but I haven't added any special code/files into my app as to increase the slug size by ~20Mb. Can you point me on how can I reduce the slug size? Any help will be greatly appreciated. Thank you very much in advance. One thing that helps is adding a .slugignore file to the root of your project

Pretty (dated) RESTful URLs in Rails

喜欢而已 提交于 2019-12-03 01:35:23
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 model to be RESTful, so things like url_for(@post) work like they should, ie: it should generate the aforementioned url. Is there a way to do this? I know you need to override to_param and have map.resources :posts with :requirements option set, but I cannot get it all to work. I have it almost done, I'm 90% there. Using resource_hacks plugin I can

Is there an easy way to populate SlugField from CharField?

那年仲夏 提交于 2019-12-02 17:27:57
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. camflan for Admin in Django 1.0 and up, you'd need to use prepopulated_fields = {'slug': ('title',), } in your admin.py Your key in the prepopulated_fields dictionary is the field you want filled, and the value is a tuple of fields you want concatenated. Outside of admin, you can use the slugify function in your views. In templates, you can use the |slugify filter. There is

Skip saving row if slug already exists in postgresql database - python

落爺英雄遲暮 提交于 2019-12-02 08:30:00
I'm setting up a function in my Django Views that calls an API and save the data into my Postgresql database. Everthing was working fine until I got an IntegrityError slugkey already exists, so I'm trying to find a way to skip or ignore the row if the slugify slug already exists. I've been stuck with this all day and I need a solution to respect expected timeline.. This is my Django Models: class Product(models.Model): destination = models.CharField(max_length=255, default='') title = models.CharField(max_length=255, default='') slug = models.SlugField(unique=True, max_length=255, default='')

TYPO3 9.5.2 Slug: Multilanguage: Page not found 404 exception, if no translation of page exists

▼魔方 西西 提交于 2019-12-02 05:24:59
问题 I have a website with two languages e.g de and en. De is my default language with no path prefix. En, the second language, has /en/ as prefix in the url. Now when I switch to the en language, the menu item links have /en/ in the url, which is fine. But when I click on a menu item, which is not explicit translated in the backend, then I get a 404 error. I cannot say this behavier is wrong, because there isn't a page with this slug path before I create one. But what should I do? Create a

How to write regular expression to match only numbers, letters and dashes?

梦想与她 提交于 2019-12-02 01:15:50
I need an expression that will only accept: numbers normal letters (no special characters) - Spaces are not allowed either. Example: The regular expression should match: this-is-quite-alright It should not match this -is/not,soålright You can use: ^[A-Za-z0-9-]*$ This matches strings, possibly empty, that is wholly composed of uppercase/lowercase letters (ASCII A-Z), digits (ASCII 0-9), and a dash. This matches ( as seen on rubular.com ): this-is-quite-alright and-a-1-and-a-2-and-3-4-5 yep---------this-is-also-okay And rejects: this -is/not,soålright hello world Explanation: ^ and $ are