【问题标题】:Error 500: .htaccess RewriteCond: bad flag delimiters错误 500:.htaccess RewriteCond:错误的标志分隔符
【发布时间】:2015-10-24 13:21:47
【问题描述】:

我注意到很多关于这个问题的问题,但就我而言,htaccess 非常简单:

<IfModule mod_rewrite.c>
RewriteEngine on

#somecomment    
RewriteBase /restAPI/   

#continue if condition is true:
RewriteCond %{REQUEST_FILENAME} !-f  # somecomment 
RewriteCond %{REQUEST_FILENAME} !-d  # somecomment 

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] 
#somecomment 
#somecomment 

</IfModule>

现在大约 4-5 周我对那个 rewritebase 没有问题,但现在我无法启动我的简单 RestAPI:/

任何建议为什么这不起作用?

【问题讨论】:

  • 尝试删除“somecomment”和 rewritecond 行的结尾?
  • 太棒了!不敢相信,但问题就在这里 - # somecomment at 8 和 9 行。

标签: .htaccess rest xampp


【解决方案1】:

好像你对这些行的评论

RewriteCond %{REQUEST_FILENAME} !-f  # somecomment 
RewriteCond %{REQUEST_FILENAME} !-d  # somecomment 

不被解释为 cmets,而是作为 RewriteCond 的参数。删除这些(或将它们移到RewriteCond 上方的行)。

IIRC cmets 仅在 Apache httpd 中的行首受支持。

【讨论】:

    【解决方案2】:
    RewriteCond %{REQUEST_FILENAME} !-f  # somecomment 
    RewriteCond %{REQUEST_FILENAME} !-d  # somecomment 
    

    500 错误是您的线路末端 cmets 的结果。 Apache 实际上并不支持 line-end cmets。

    以散列字符“#”开头的行被视为 cmets,并被忽略。注释可能与配置指令位于同一行。

    参考:https://httpd.apache.org/docs/2.2/configuring.html#syntax

    由于“侥幸”,有时行端 cmets 似乎可以工作。如果您向指令提供所有参数,则该行后面的任何内容都将被忽略。但在这种情况下,您没有提供任何 flags(第三个参数),因此您收到错误消息,它试图将您的 # somecomment 解释为 RewriteCond 标志。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-13
      • 1970-01-01
      • 2014-06-23
      • 2015-02-04
      • 2017-10-04
      • 2014-12-21
      相关资源
      最近更新 更多