Search code examples
apache.htaccessmod-rewrite

Apache mod_rewrite - unknown flag 'AND'


These rules are not working on apache 2.2.34

RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com$ [NC,AND]
RewriteCond %{QUERY_STRING} ^(.*)$ [NC]
RewriteRule ^/page\.php$ - [R=404,L]

I get RewriteCond: unknown flag 'AND'

Is there any other way to do this?


Solution

  • AND is not required (and not a valid flag either) as conditions are automatically ANDed together.

    just use:

    RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com$ [NC]
    

    Moreover RewriteCond %{QUERY_STRING} ^(.*)$ [NC] is not really doing anything and it matches QUERY_STRING with anything (including empty string).

    Your final rul should be just this:

    RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com$ [NC]
    RewriteRule ^/?page\.php$ - [R=404,NC,L]