Apache mod_rewrite:如何 "whitelist" 网址?

Apache mod_rewrite: How to "whitelist" urls?

我正在使用 mod_rewrite 来获得更好的网址。所以目前有两种访问页面的方式:

访问站点的唯一方式应该是mod_rewrite。换句话说,我想 "whitelist" 某些 uri 并阻止每个不同的 uri。

我想过要有一个带有 "END" 标志的 RewriteRules 列表,所以如果上述规则中的 none 匹配,最后一个将阻止请求。这有效,但它也阻止了我的 index.php 站点。此外,这 "feel" 并不是最好的方法。

可以使用 RewriteCond 将某些页面列入白名单,并使用 RewriteRule 捕获所有响应 404 错误。

# if the request uri is not /mypage.php and /otherpage.php
RewriteCond %{REQUEST_URI} !^/(mypage|otherpage)\.php

# if the request uri is not /startpage
RewriteCond %{REQUEST_URI} !^/startpage

# response 404 error
RewriteRule ^ - [R=404,L]