Home Apache mod_rewrite: How to "whitelist" urls?
Reply: 1

Apache mod_rewrite: How to "whitelist" urls?

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 Reply to 2018-01-09 17:36:25Z

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]
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.323547 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO