SQL Replace för att skapa Slugs

Har på många tidigare projekt använt Id-nummer i url:erna för att IIS och .NET haft så dåligt stöd för att skapa användarvänliga url:er. Gör nu om en del gamla sidor till ASP.NET MVC och lägger över dem till IIS 7-servrar som har bättre stöd för url-omskrivning.

Brukar lägga till ett speciellt databas-fält för att spara den sista delen av url:en som ska vara till för att identifiera blogginlägget, produkten, kategorien eller vad det nu handlar om och basera denna på den äldre titeln. Använder det uttryck som även Wordpress använder för att beskriva ett sånt fält, "Slug".

Här är ett skript som jag precis körde på en sådan databas. Detta byter ut de tecken jag inte vill ha i url:erna mot ett vanligt bindestreck, gör om allt till gemener och byter ut å,ä,ö mot a,a,o.

UPDATE BlogPost SET Slug=Lower(Title);
UPDATE BlogPost SET Slug=REPLACE(Slug,'å','a');
UPDATE BlogPost SET Slug=REPLACE(Slug,'ä','a');
UPDATE BlogPost SET Slug=REPLACE(Slug,'ö','o');
UPDATE BlogPost SET Slug=REPLACE(Slug,' ','-');
UPDATE BlogPost SET Slug=REPLACE(Slug,'&','-');
UPDATE BlogPost SET Slug=REPLACE(Slug,'/','-');
UPDATE BlogPost SET Slug=REPLACE(Slug,'-','-');
UPDATE BlogPost SET Slug=REPLACE(Slug,'.','-');
UPDATE BlogPost SET Slug=REPLACE(Slug,',','-');
UPDATE BlogPost SET Slug=REPLACE(Slug,'_','-');

Comments

hej har problem med en kontakt form på www.l"> www.låstadhemnära.se den viser äåö medkonstig bokstaver plus att det går ikke att se hjälp mej

Hej! Tack, detta var användbart! Jag kan tipsa om att även byta ut '+' som jag haft problem med i url:er.

Fridens

Hej! Tack, detta var användbart! Jag kan tipsa om att även byta ut '+' som jag haft problem med i url:er.

Fridens

Hej! Tack, detta var användbart! Jag kan tipsa om att även byta ut '+' som jag haft problem med i url:er.

Fridens

I merely wanted to state hey there and also exhibit my personal thanks for the tips supplied. www.cfsflooring.co.uk

Your post is awesome full of knowledge.

More about engineering college in delhi Top Engineering college in Delhi NCR

Very nice quarries for SQL slugs. thanks for providing best information.

Very nice quarries for SQL slugs. thanks for providing best information.

http://www.janbaskdigitaldesign.com

Very nice quarries. thanks for providing best information. thanks http://www.onlinepromotionuae.ae

Hello Thanx for the sharing this article which very important

thanks for sharing a nice information....... www.andamandiscover.com"> www.andamandiscover.comlink text

Your post is really good full of knowledgeable and thanks for sharing with us.... http://onlinepromotionhouse.com"> http://onlinepromotionhouse.comlink text

I am really enjoying reading your well written post.When if you can get complete computer technical support so consult at the HP technical support team is there for you. Just uses the HP Help Number UK toll free 0800-098-8371

Superb post. Many thanks for discussing valuable content material. Best Technical Support for Microsoft user. If you face any types of problems you can touch with : Microsoft Support Number UK Microsoft Help Number UK Microsoft Contact Number UK

Very Very nice post. its a very useful and outstanding article. Thanks for that. epson support number

Thanks for sharing nice information with us. Lenovo Support Number UK Lenovo Help Number UK Lenovo Helpline Number UK

very very nice article, thanks for the sharing with us.

Toshiba Tech Support

Very Very nice post. its a very useful and outstanding article. Thanks for that.Call@ 0800-098-8569 for Windows Support Number, Windows XP support, Windows 10 Support, Windows 8 help, Windows Phone Support, Windows Tech Support, Windows 7 Support.

Windows 8 help

The system works slowly or system just unable to remove to previous antivirus after its installation is the issue that you can resolve by dialing 0800-098-8371 UK. The expert technicians are ready to sort out the issues. More help you can touch with McAfee Help Number UK McAfee Phone Number UK McAfee Support Number UK

yes man, its a very useful article. i tried it on my sites. its work. thank you so much. norton customer support number uk Norton Support Norton Support Number

Today I learned a lot from your website. thank you hp laptop support uk

Hii, Thanks for the sharing nice posting with us. i’m really impressed.

Thanks for this awesome web page, i like it.

microsoft office support email

microsoft office technical support phone number

innovative information is here. good

This is outstanding and great post! i really like it.thank you so much. avg support number

Please fill out all the fields.

*
*