doddsey_65 Posted September 19, 2011 Share Posted September 19, 2011 When a user clicks on a topic they are transfered to its post, which is retrieved by the name of the topic as given by the url value. up to now i have just used urlencode. But its trickier when a user adds slashes and dots into the mix. for example the title of the post is testing/testing. The url will go to www.asimpleforum.co.uk/t/testing/testing. How would i get around this since url encode doesnt do the job? I could replace slashes and dots with their own unique symbol but that produces the problem when someone uses one of those symbols that i use to replace in their topic title. I know one site in particular that replaces all dots and slashes with a hyphen (-), but how would you know what to turn the hyphen into when you query the database for that topic? Anyone have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/247412-custom-url-encoding/ Share on other sites More sharing options...
Adam Posted September 19, 2011 Share Posted September 19, 2011 There's a few ways of doing it. 1) Include an ID within the URL, making the post title redundant beyond SEO purposes. This would be best performance wise and you never have to worry about collisions. 2) As you query the database, you can pass the title column's value through an identical string manipulation process for comparison. Least preferable for performance, and dealing with collisions would be more complex (how many posts on here are created with "HELP!" or something?) 3) Or lastly, and the most clean way in terms of SEO, would be to store the post title within the database and look-up based on that. You could add a unique index to improve performance, and deal with collisions as you insert the row. Edit Just to be clear, this how you would solve the issues if you convert the slash to a hyphen - which I definitely recommend. Quote Link to comment https://forums.phpfreaks.com/topic/247412-custom-url-encoding/#findComment-1270587 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.