Home Apache mod_rewrite: How to "whitelist" urls?

# Apache mod_rewrite: How to "whitelist" urls?

Antict
1#
Antict Published in 2018-01-08 18:38:02Z
 I'm using mod_rewrite to get better urls. So currently there are two ways to access a page: Direct Access: http://example.org/mypage.php Access with mod_rewrite: http://example.org/startpage The only way possible to access the site should be with mod_rewrite. In other words, I want to "whitelist" certain uris and block every different uri. I thought about having a list of RewriteRules with "END" flag, so if none of the above rules matches, the last one will block the request. This works, but it also blocks my index.php site. Furthermore, this doesn't "feel" like the best way to do it.
Ben
2#
 Can use RewriteCond to whilelist certain pages, and RewriteRule to catch-all responses 404 errors. # 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]