Stone
Stone

Reputation: 343

How to compare HTTP_HOST with SERVER_NAME in .htaccess?

I tried the following but does not seem to work:

# IF HTTP_HOST != SERVER_NAME DO 403
RewriteCond %{HTTP_HOST} !%{SERVER_NAME} [NC]
RewriteRule .* - [F,L]

Upvotes: 1

Views: 613

Answers (1)

anubhava
anubhava

Reputation: 785146

You cannot use a variable on RHS of RewriteCond. Use it like this:

RewriteCond %{SERVER_NAME}#%{HTTP_HOST} ^(?:www\.)?([^#]+)#(?!(www\.)?\1).* [NC]
RewriteRule .* - [F,L]

Upvotes: 1

Related Questions