I am using this .htaccess :

RewriteEngine On
RewriteCond %{HTTP_HOST} *!^www*.kerala\.local [NC]
RewriteRule (.*) http://www.kerala.local/$1 [L,R=301] 

I am getting the error in browser:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@cyberotech.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

The /var/log/apache2/error.log says:

RewriteCond: cannot compile regular expression '*!^www*.kerala\\.local'
有帮助吗?

解决方案

Your regex is indeed wrong. (there are stray asterisks)

Use this code instead:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301] 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top