RewriteCond在.htaccess文件给我坏标志分隔符

我正在升级一个网站,我用这个.htaccess文件来显示维护页面:

#MAINTENANCE-PAGE REDIRECT RewriteEngine on RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.0 # Bogus IP address for posting here RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.0 # Bogus IP address for posting here RewriteCond %{REQUEST_URI} !^/maintenance\.html$ RewriteRule ^(.*)$ http://www.mysite.no/maintenance.html [R=307,L] 

这将打开所有用户的维护页面,除了我添加的两个IP地址。 他们得到一个Internal Server Error 。 我在另一个网站上使用了相同的脚本,并且工作正常。

看看错误日志,我看到以下内容:

 /var/www/vhosts/mysite.no/httpdocs/.htaccess: RewriteCond: bad flag delimiters 

如果我删除我的.htaccess文件,我可以使用我的网站就好了。

我的网站使用CentOS 5托pipe在VPN上。

我该如何解决这个问题?

我相信你必须使用[OR]标志来链接这样的规则:

 #MAINTENANCE-PAGE REDIRECT RewriteEngine on RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.0 [OR] RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.0 [OR] RewriteCond %{REQUEST_URI} !^/maintenance\.html$ RewriteRule ^(.*)$ http://www.mysite.no/maintenance.html [R=307,L] 

在Apache文档中,它以本节的底部为例: http : //httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond

另外,您可以使用RewriteLogRewriteLogLevel 3指令来获得更多的信息。

有些事情要尝试/检查:

  • 确保mod_rewrite在apache中被加载和启用。
  • 确保FileInfo覆盖允许(使用AllowOverride.htaccess文件。
  • 从您的RewriteCond行删除评论。