Using mod_rewrite to 301 to SERVER_NAME
问题 I have many ServerAlias'es in my Apache vhost and I want all domains that aren't the ServerName to be 301'ed to the ServerName. This is not working: RewriteCond %{HTTP_HOST} !%{SERVER_NAME} [NC] RewriteRule ^(.*)$ http://%{SERVER_NAME}/$1 [R=301,QSA,L] This does work: RewriteCond %{HTTP_HOST} !www.some-domain.com [NC] RewriteRule ^(.*)$ http://%{SERVER_NAME}/$1 [R=301,QSA,L] Can I do this without hard coding the domain name? 回答1: Environment variables are only expanded on the left hand side