regex - 重写条件 : cannot compile regular expression

标签 regex apache .htaccess rewrite

我正在使用这个 .htaccess :

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

我在浏览器中遇到错误:

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.

/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] 

关于regex - 重写条件 : cannot compile regular expression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21906067/

相关文章:

apache - ulimit : error setting limit - Operation not permitted - (using apachectl in container on ECS)

java - java中的循环定界符,消息损坏到数组

javascript - 为什么这个 RegExp exec 会导致无限循环?

regex - GNU grep regex `[一-十]`(一到十)不匹配汉字四(四)

apache - Mac OS X - Apache 路径? Apache 上的 ruby ?

linux - .htaccess 隐藏文件- url 栏

regex - RewriteCond 无法对 HTTP_HOST 强制使用 https

apache - 使用 Apache 的本地主机的自签名 SSL 证书

php - laravel 5 (JTW) 登录失败

apache - RewriteRule 给了我不需要的 $_GET 参数