0
votes

I have some form on the website where users can add new pages. I must generate SEO friendly URLs and make this URLs unique. What characters can I display in URL, I know that spaces I should convert to underscore:

" "->"_" and before it - underscores to something else, for example:

"_"->/underscore

It is easy make title from URL back.

But in my specific title can be all characters from keyboard, even : @#%:"{/\';.>

Are some contraindications to don't use this characters in URL?

Important is:

-easy generating URL and title from URL back (without queries to database)

-each title are unique, so URL must be too

-SEO friendly URLs

1

1 Answers

1
votes

Aren't you querying the database to get the content anyway? In which case just grab the title field in the same query.

The only way to reliably get the title back from the URL is to 'URL encode' it (in PHP you use the urlencode() function). However, you will end up with URLs like this:

My%20page%20title

You can't replace any characters because you will then not have unique URLs. If you are replacing spaces with underscores, for example, the following titles will all produce the same URL:

My page title
My_page title
My_page_title

In short: don't worry about one extra database hit and just use SEO-friendly URLs by limiting to lowercase a-z, 0-9 and dashes, like my-page-title. Like I said, you can just grab everything in one query anyway.