Apache .htaccess文件中的mod_重写规则有问题

Apache .htaccess文件中的mod_重写规则有问题,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,这是我的.htaccess文件,但它不工作。没有任何URL被重定向。帮帮我 RewriteEngine on RewriteRule ^home index.php RewriteRule ^contactus index.php?file=c-contactus RewriteRule ^course_registration index.php?file=c-course_registration RewriteRule ^ncplhpage index.php?file=c-ncplhpa

这是我的.htaccess文件,但它不工作。没有任何URL被重定向。帮帮我

RewriteEngine on
RewriteRule ^home index.php
RewriteRule ^contactus index.php?file=c-contactus
RewriteRule ^course_registration index.php?file=c-course_registration
RewriteRule ^ncplhpage index.php?file=c-ncplhpage
RewriteRule ^scplhpage index.php?file=c-scplhpage
RewriteRule ^corporatetra index.php?file=c-corporatetra

您可能需要设置一个基础

但是,我怀疑问题在于在所有情况下都缺少a/before index.php,即

RewriteEngine on
RewriteRule ^home /index.php
作为补充,您是否考虑过将指令合并为一个指令,如:

RewriteRule ^(home|contactus|course_registration|ncplhpage|scplhpage|corporatetra)$ /index.php?file=c-$1
??您可以更进一步,将名称的检查交给index.php文件本身,即

RewriteRule ^([_a-z]+)$ /index.php?file=c-$1
请记住,index.php应该检查所请求的$\u GET['file']是否有效。仅仅因为你有像/contactus这样的公共URL并不意味着有人仍然不能直接输入/index.php?file=c-contactus试试吧!。这意味着他们可以输入/index.php?file=c-../../../../../etc/passwd。因此,请确保index.php也执行一些健全性检查。这将有利于安全性,但也意味着您可以避免将URL硬编码到.htaccess文件中