【问题标题】:RewriteCond: cannot compile regular expressionRewriteCond:无法编译正则表达式
【发布时间】:2023-04-07 23:13:01
【问题描述】:

我正在使用这个 .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'

【问题讨论】:

    标签: regex apache .htaccess rewrite


    【解决方案1】:

    您的正则表达式确实是错误的。 (有杂散星号)

    改用此代码:

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

    【讨论】:

    • 它正在工作,。你能提供一个不考虑域名的通用解决方案吗
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-30
    • 1970-01-01
    • 1970-01-01
    • 2013-03-10
    • 1970-01-01
    相关资源
    最近更新 更多