doubledee Posted August 8, 2011 Share Posted August 8, 2011 What is the difference between separating words with a plus ("+") versus a hyphen ("-") versus an underscore ("_") when creating "pretty URLs"? Are all three valid? What does Google think? Debbie Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/ Share on other sites More sharing options...
cunoodle2 Posted August 8, 2011 Share Posted August 8, 2011 To me often a plus represents a space. I would do a dash as that seems to be the most common. The underscore is probably sufficient too but not as often used. Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1254013 Share on other sites More sharing options...
Psycho Posted August 8, 2011 Share Posted August 8, 2011 I think you are putting more work into this than you need to. There is already a function in PHP to convert a vaue into an URL acceptable value. urlencode(). You would then use the opposite command, urldecode() on the values passed through $_GET to convert them back to their original value. Using the urlencode() function, spaces are converted to plus signs. Other "special" characters are converted into appropriate codes. Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1254048 Share on other sites More sharing options...
doubledee Posted August 8, 2011 Author Share Posted August 8, 2011 I think you are putting more work into this than you need to. There is already a function in PHP to convert a vaue into an URL acceptable value. urlencode(). You would then use the opposite command, urldecode() on the values passed through $_GET to convert them back to their original value. Using the urlencode() function, spaces are converted to plus signs. Other "special" characters are converted into appropriate codes. Good point, but I am manually determining how to convert "Postage Meters: A Great Way to Save Money" to "postage-meters-a-great-way-to-save-money", so that is why I asked. I've always liked underscores for spaces, but it seems the web mainly uses pluses and hyphens. Debbie Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1254051 Share on other sites More sharing options...
phpSensei Posted August 8, 2011 Share Posted August 8, 2011 Consider using punctuation in your URLs. The URL http://www.example.com/green-dress.html is much more useful to us than http://www.example.com/greendress.html. We recommend that you use hyphens (-) instead of underscores (_) in your URLs. I think you should consider how search engines will pick up the URLs also.. So its best not to user underscores. Have a read here http://www.google.com/support/webmasters/bin/answer.py?answer=76329 Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1254080 Share on other sites More sharing options...
Psycho Posted August 8, 2011 Share Posted August 8, 2011 That quote is regarding using punctuation in the "base" url - in that case the file name. The OP's question is regarding parameters on the URL. Even Google uses the plus symbol for spaces in the search term. Do a google search for multiple words and check the URL that is generated when you click the search button. Granted there are a ton of parameters generated, but the parameter for "q" will show the search terms separated by a plus symbol. It is inadvisable to come up with your own logic for this. The plus symbol is the internet standard. If you ever wanted to pass information to another service or receive information from another service more work would be required to do so if you aren't following standard protocol. Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1254350 Share on other sites More sharing options...
JasonLewis Posted August 8, 2011 Share Posted August 8, 2011 In reference to the "pretty URLs" part and not encoding your URLs, typically a hyphen is favored over an underscore. But that doesn't mean underscores aren't used. You check any Wiki and 99% of the time (if using MediaWiki) the page titles use underscores for separation. It's not common in most websites but I've seen it around. Personally I favor the hyphens, but you can use what you want. Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1254357 Share on other sites More sharing options...
doubledee Posted August 11, 2011 Author Share Posted August 11, 2011 In reference to the "pretty URLs" part and not encoding your URLs, typically a hyphen is favored over an underscore. But that doesn't mean underscores aren't used. You check any Wiki and 99% of the time (if using MediaWiki) the page titles use underscores for separation. It's not common in most websites but I've seen it around. Personally I favor the hyphens, but you can use what you want. So it sounds like hyphens are best as far as Search Engines are concerned. However, how would you format this Article Title which will become the "pretty" URL... Protecting Your Money: Debbie's Story (I think it is important to use a non-hyphen for the colon to denote two separate thoughts/parts.) 1.) protecting-your-money-debbies-story 2.) protecting-your-money_debbies-story 3.) protecting-your-money+debbies-story Other? Debbie P.S. How do you handle where the apostrophe should be when it comes to the URL? Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1255694 Share on other sites More sharing options...
gizmola Posted August 11, 2011 Share Posted August 11, 2011 Strip out any punctuation characters, quotes, hyphens etc. They are not needed in the slug and will not help with google. All you require is something that has words in it that basically match the article title. Just stick with hyphens for spaces ... so basically: -strip out all punctuation -replace spaces with - And use that for your slug. This is partly functional (characters that are ok in url's without url encoding) , and partly "search engine friendly" and "search engine optimization" strategies you are focusing on. As mjdamato pointed out, you could take the exact title with punctuation and spaces and url encode that, and it will be fine with google. It just won't look friendly to your visitors, and may discourage them from bookmarking it. So for that reason, you really want to remove all the punctuation characters and basically anything else that would have to be url encoded. Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1255698 Share on other sites More sharing options...
doubledee Posted August 11, 2011 Author Share Posted August 11, 2011 Strip out any punctuation characters, quotes, hyphens etc. They are not needed in the slug and will not help with google. All you require is something that has words in it that basically match the article title. Just stick with hyphens for spaces ... so basically: -strip out all punctuation -replace spaces with - And use that for your slug. This is partly functional (characters that are ok in url's without url encoding) , and partly "search engine friendly" and "search engine optimization" strategies you are focusing on. As mjdamato pointed out, you could take the exact title with punctuation and spaces and url encode that, and it will be fine with google. It just won't look friendly to your visitors, and may discourage them from bookmarking it. So for that reason, you really want to remove all the punctuation characters and basically anything else that would have to be url encoded. Okay. (I'd prefer "protecting-your-money_debbies-story", but oh well?!) Debbie Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1255981 Share on other sites More sharing options...
phpSensei Posted August 11, 2011 Share Posted August 11, 2011 Strip out any punctuation characters, quotes, hyphens etc. They are not needed in the slug and will not help with google. All you require is something that has words in it that basically match the article title. Just stick with hyphens for spaces ... so basically: -strip out all punctuation -replace spaces with - And use that for your slug. This is partly functional (characters that are ok in url's without url encoding) , and partly "search engine friendly" and "search engine optimization" strategies you are focusing on. As mjdamato pointed out, you could take the exact title with punctuation and spaces and url encode that, and it will be fine with google. It just won't look friendly to your visitors, and may discourage them from bookmarking it. So for that reason, you really want to remove all the punctuation characters and basically anything else that would have to be url encoded. I see, I am going to take your advice on this also. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1256093 Share on other sites More sharing options...
gizmola Posted August 11, 2011 Share Posted August 11, 2011 You can use the underscore if you really want -- it's neither here nor there. It won't be a benefit nor will it be a hinderance to anything that is important. Of course there are other strings of characters that could be in a title as alluded to previously. For example, '--', '...'. It is perfectly fine to substitute an underscore for a colon, but from a logical standpoint, what do you gain of value by adding that complexity? The slug has no importance other than: -to pass as a parameter to find the article in the database -to reinforce using words, the title and text of the article, which *may* be of value to some search engines. -to make nicer bookmarks for people, so that when looking in a bookmark list, they might recognize it some time later when they want to refer back to it Considering this, it's just cleaner to exclude the colon or a special replacement for it, and hopefully it's clear that any consideration of the colon is not important, but if you really want to replace it with an underscore it's not going to hurt anything. Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1256096 Share on other sites More sharing options...
doubledee Posted August 12, 2011 Author Share Posted August 12, 2011 Gizmola, Okay, so taking things one step forward, what about my meta tags? Would you favor... <meta name="keywords" content="Postage Meters can save you money!" OR <meta name="keywords" content="Postage-Meters can save you money!" OR <meta name="keywords" content="postage-meters-can-save-you-money" Debbie Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1256188 Share on other sites More sharing options...
gizmola Posted August 12, 2011 Share Posted August 12, 2011 Keywords are meant to be a list of "key" words, typically comma seperated. However, Google for one, just ignores them: http://googlewebmastercentral.blogspot.com/2009/09/google-does-not-use-keywords-meta-tag.html Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1256240 Share on other sites More sharing options...
doubledee Posted August 12, 2011 Author Share Posted August 12, 2011 Keywords are meant to be a list of "key" words, typically comma seperated. However, Google for one, just ignores them: http://googlewebmastercentral.blogspot.com/2009/09/google-does-not-use-keywords-meta-tag.html My bad. I wrote the wrong thing. Can you please re-answer my question above but replace "keywords" with "description". Thanks, Debbie Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1256400 Share on other sites More sharing options...
JasonLewis Posted August 12, 2011 Share Posted August 12, 2011 The same would apply doubledee, there would be no benefit (probably more of a bad thing if anything) from doing that. Google does use the description meta tag for page descriptions on search results. They don't do it all the time, but some of the time they will. It'd be pretty ugly seeing a search result that consisted of a description with hyphenated words. You'd be better off giving each of your pages a unique and well written (yet still short) description and Google will love you. Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1256466 Share on other sites More sharing options...
doubledee Posted August 12, 2011 Author Share Posted August 12, 2011 The same would apply doubledee, there would be no benefit (probably more of a bad thing if anything) from doing that. Google does use the description meta tag for page descriptions on search results. They don't do it all the time, but some of the time they will. It'd be pretty ugly seeing a search result that consisted of a description with hyphenated words. You'd be better off giving each of your pages a unique and well written (yet still short) description and Google will love you. Okay, good point! (Sorry, been low on sleep!!) Debbie Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1256522 Share on other sites More sharing options...
gizmola Posted August 12, 2011 Share Posted August 12, 2011 With description, it should be whatever text provides a summary of the content for that page. Many times, google will display what you have in your Description in their search results. Url's don't factor into it. So in your examples above, example #1 would be the closest. The google blog is often a good source for some information on how they look at it: http://googlewebmastercentral.blogspot.com/2007/09/improve-snippets-with-meta-description.html Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1256553 Share on other sites More sharing options...
doubledee Posted August 12, 2011 Author Share Posted August 12, 2011 With description, it should be whatever text provides a summary of the content for that page. Many times, google will display what you have in your Description in their search results. Url's don't factor into it. So in your examples above, example #1 would be the closest. The google blog is often a good source for some information on how they look at it: http://googlewebmastercentral.blogspot.com/2007/09/improve-snippets-with-meta-description.html Thanks for the link. All stuff I already *strive* to do. Thanks, Debbie Quote Link to comment https://forums.phpfreaks.com/topic/244178-pretty-urls-and-_/#findComment-1256562 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.