How does mod_rewrite work?

Please help solve a debate!

I am in somewhat of an argument with a forum developer regarding “friendly seo” urls.

What they are saying:

Having the “ID” of the thread in the URL is necessary because if it wasn’t, the database query would change from:

SELECT * FROM topics WHERE tid=X;
to:
SELECT * FROM topics WHERE title_seo=X;

My question to you guys is:
Does mod_rewrite change the way databases are queried when a user visits a link?

For example:

If you visit this topic from a link someone posts elsewhere you’re going to be linked to this
sitepoint.com/forums/showthread.php?1197439-Renamed-directories-to-sub-domain
So, lets take your proposal and remove the ID
sitepoint.com/forums/showthread.php?Renamed-directories-to-sub-domain
The only way to find the content is from the title. So you HAVE to do an initial search of the database using the title in order to get the topic ID. You can’t search by topic ID if you don’t have it in the URL.

Additional, my next question is even if this is true, how much of an effect would this have on those database queries? In other words, would it make the queries so inefficient that it would bring the server down or cause a decrease in load times?

My argument is that the forum URLs should adopt the way WordPress’s permalink structure works. ID’s should not be included in URLs.

Their opinion is no, because it would be “inefficient”, that for super-large forums, the “index” would be so big for the topic titles to do the query that it would take too long, create a bottleneck and bring down the server. They haven’t even entertained the idea of testing this, but this is their opinion.

Hi, welcome to the forums

If the same title was used more than once, how would you differentiate, or would you?
Using an id makes it easy, otherwise you would need to append something to titles or put them in “folders” to make them unique

The same way WordPress forums are run:

http://wordpress.org/support/topic/wp-installed-in-subfolder

If I created a new thread “wp installed in subfolder” the URL would come out as:

http://wordpress.org/support/topic/wp-installed-in-subfolder-2

Yes, I’ve posted many times on this subject and have used http://wilderness-wally.com as my working example (of using the title rather than a numeric ID). Note that Alan (Mitt) is correct as the title field MUST be made unique (best to enforce in the table structure) to prevent duplicate keys. However, WP already enables this (with a click in its admin) so I’m not sure what the argument is about (if you’re using WP, it’s best to use its modules to select how links are created then used in its database query). If you’re doing this by hand, though, Wilderness Wally has demonstrated how easily this is done (by a client who only knows [A] not to duplicate titles and [B] which characters must be avoided - it’s a URI ‘thing,’ not a mod_rewrite limitation).

Regards,

DK

Thank you for the response.

The developer/group I’m discussing this with is from Invision Power Board – it’s regarding their upcoming forum software.

The WordPress example I used is how WordPress’s forum (bbpress) is based.

No problem. On the other hand, did I answer your question for you?

Note, too, that I have complained about WP’s mod_rewrite code but they do have a valid reason for much of it AND, if you’re creating a new app similar to WP, there are some things that its developers must consider, e.g., the acceptable characters (allowed in a URI - check http://www.ietf.org/rfc/rfc2396.txt) and make sure that the titles are required to be unique (enforced by the database [MySQL does this but I’m not sure about other databases]). IF unique titles (or whatever field you use as a key) are not possible, then you’ll have to do what SitePoint does, i.e., use both the ID and title in the URI (ARGH! That’s UGLY!) and have the query search for the ID.

Regards

DK