Either your question is unclear or you have not (yet) really thought this through... If you want to rewrite pretty URLs into an internal request that refers to some specific object inside your data model, then you do need that object's ID inside the URL. Simply because the http servers rewriting logic cannot somehow guess that (typically numeric) ID somehow.
So I assume you want to finally use URLs along this scheme:
For that situation you'd need a rewriting set like this:
RewriteEngine on
RewriteRule ^/?subjects/(\w+)/(\d+)$ /subjects.php?subject=$1&subjectid=$2 [END]
RewriteRule ^/?topics/(\w+)/(\d+)$ /topics.php?topic=$1&topic_id=$2 [END]
RewriteRule ^/?quizzes/(\w+)/(\d+)$ /quizzes.php?quizz=$1&id=$2 [END]
I personally would not use different names for the ID comlumn, but that is a question of personal choice and of how you internally match, I guess.
The above rule set will work in the http servers host configuration and likewise inside some dynamic configuration file (".htaccess
" style file). you obviously need to have the http servers rewriting module loaded and activated. In case you decide to use a dynamic configuration rule also need to make sure that it's interpretation is enabled (see the AllowOverride
directive in the documentation) and that the file is located in the http hosts DOCUMENT_ROOT
and readable by the server process.
In case you get a http status 500 back for requests to those URLs ("internal server error"), then chances are that you operate a very old version of the apache http server. In that case try using the [L]
flag instead of the [END]
flag.
And a general hint: you should always prefer to place such rules inside the http servers (virtual) host configuration instead of using dynamic configuration files (.htaccess
style files). Those files are notoriously error prone, hard to debug and they really slow down the server. They are only supported as a last option for situations where you do not have control over the host configuration (read: really cheap hosting service providers) or if you have an application that relies on writing its own rewrite rules (which is an obvious security nightmare).