RewriteEngine on
RewriteRule ^192.168.20.87$ nothing
For some reason if I do it with .htaccess it works
Although this won't match the URL http://192.168.20.87/page.php
even if you "do it with .htaccess
", so you must be doing something else?
The above rule (when used in a <Directory>
container) matches a URL of the form http://192.168.20.87/192.168.20.87
(or http://default.nothing/192.168.20.87
- if your hostnames resolve).
The RewriteRule
pattern matches the URL-path only, not the hostname (ie. 192.168.20.87
). So, this matches against /page.php
, (or page.php
- relative path/no slash prefix - when used in a directory context like <Directory>
or .htaccess
.)
So this would need to be like the following instead:
RewriteRule ^page\.php$ nothing
(Although it's unclear what you are trying to do here, what is "nothing"? If you are trying to trigger a 404 then this is not really the way to do it.)
As @Gerrit loosely mentioned in comments, when the RewriteRule
directive is used in a server or virtualhost context (ie. not in <Directory>
or .htaccess
containers - a directory context) then the URL-path matched by the RewriteRule
directive is root-relative, starting with a slash, because the directive is processed much earlier, before it has been mapped to the file system. eg. ^/page\.php$
.
UPDATE:
DocumentRoot /var/www/html/public_html/00-default
<Directory "/volume/dev/html/public_html/00-default">
I've just noticed that your DocumentRoot
and <Directory>
directives are referencing two different filesystem locations?! With the limited information in the question, this <Directory>
container is never going to be processed.
But unless you have additional directives elsewhere (which I assume you must have) then any .htaccess
file placed in the document root (which is where I assume you are putting it) is never going to be processed either.