开发者

What is the best way to do SO style routes (dashes as spaces)

Just wondering what the best way to do SO style routes is.

What is the best way to do SO style route开发者_如何学Pythons (dashes as spaces)

What's the best way to create routes like this?


I've found ASP.NET MVC and Clean SEO Friendly URLs on Dominic Pettifer's blog.

It works on a white-list principle, allowing all 0-9 and a-z characters through, dealing with a few special cases, and converting everything else to -hyphens-. You'll notice that spaces are being converted to hyphens as well, and you might be tempted to use underscores instead. Don't! There are sound SEO benefits for using hyphens in that search engines bots treat them as spaces.


Here's one way.

Here's another.

It's called a slug btw.


I think the best way would be to replace any non-alphanumeric character with a dash. You could search for this regex [^\w]+ and replace with -.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜