I have software with student, teacher and admin part. I want to allow teacher to choose their web address such as http://mydomain.com/teacher1, http://mydomain.com/teacher2 etc.
How can I use this mod_rewrite for that? This part is working:
RewriteEngine On
RewriteRule username teacher/
but not when I have some link in teacher dir such as teacher/training.php browser open index.php page in teacher/dir instead of training.php.
mod_rewrite reads all of the path and modifies it all. The format is: “RewriteRule pattern substitution” (Apache Docs)
“Pattern” can be a substring and anything that matches that substring will be rewritten, but “substitution” is the full path.
Assuming that you want “username” to only match at the start, and assuming that all locations under it must be rewritten, what you need is:
That will ignore “username” but append the rest of the path on the end, so
http://example.com/username/training.phpwould show the content for (but not change the address to)http://example.com/teacher/training.php. If you want it to do a full redirect so that the URL changes, add[R=301]at the end of theRewriteRuleline.