Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 重写条件:无法编译正则表达式_Regex_Apache_.htaccess_Rewrite - Fatal编程技术网

Regex 重写条件:无法编译正则表达式

Regex 重写条件:无法编译正则表达式,regex,apache,.htaccess,rewrite,Regex,Apache,.htaccess,Rewrite,我正在使用此。htaccess: RewriteEngine On RewriteCond %{HTTP_HOST} *!^www*.kerala\.local [NC] RewriteRule (.*) http://www.kerala.local/$1 [L,R=301] 我在浏览器中遇到错误: 内部服务器错误 服务器遇到内部错误或配置错误,无法正常运行 无法完成您的请求 请与服务器管理员联系,webmaster@cyberotech.com及 通知他们错误发生的时间,以及您可能需要的

我正在使用此。htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} *!^www*.kerala\.local [NC]
RewriteRule (.*) http://www.kerala.local/$1 [L,R=301] 
我在浏览器中遇到错误:

内部服务器错误

服务器遇到内部错误或配置错误,无法正常运行 无法完成您的请求

请与服务器管理员联系,webmaster@cyberotech.com及 通知他们错误发生的时间,以及您可能需要的任何信息 这样做可能会导致错误

有关此错误的详细信息,请参阅服务器错误 日志

/var/log/apache2/error.log
说明:

RewriteCond: cannot compile regular expression '*!^www*.kerala\\.local'

你的正则表达式确实错了。(有零散的星号)

请改用此代码:

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

它正在工作,。你能提供一个通用的解决方案而不考虑域名吗