Apache mod_rewrite没有正确链接

am new to PHP, apache, been trying to do the mod_rewrite thing this is code it is supposed to rewrite from localhost/main/teacher/index.php?subj=departments to localhost/main/staff/department. if I type the link localhost/main/staff/departments it works but Whenever I click on the link it gives localhost/main/staff/index.php?subj=department.

Here is my .htaccess code:

RewriteEngine On
Rewrite ^staff/(.+)$    teacher/index.php?subj=$1   [NC, L]

Here's what you should have in your .htaccess file:

RewriteEngine On
RewriteRule ^staff/(.+)$    teacher/index.php?subj=$1 [NC]

Note the second line starts with RewriteRule, not Rewrite. Also, you need to remove the L flag from this rule.

You can read more about the flags here.

I wish someone would improve the answer and explain in detail why NC, L doesn't work, while NC alone works.