错误500:.htaccess RewriteCond:坏标记分隔符

时间:2015-08-02 09:03:36

标签: .htaccess rest xampp

我注意到很多关于这个问题的问题,但就我而言,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周我对重写库没有问题,但现在我无法启动我的简单RestAPI:/

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

2 个答案:

答案 0 :(得分:2)

好像你的评论就行了

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

不会被解释为评论,而是作为RewriteCond的参数。删除它们(或在RewriteCond上方的行上移动它们。)

仅在Apache httpd。

中的一行开头支持IIRC注释

答案 1 :(得分:1)

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

500错误是您的行结束注释的结果。 Apache实际上并不支持行结尾注释。

  

以井号字符开头的行&#34;#&#34;被视为评论,被忽略。评论可能与配置指令包含在同一行。

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

有时,行尾注释似乎正常工作因为&#34; fluke&#34;。如果提供指令的所有参数,则忽略该行尾随的任何内容。但在这种情况下,您还没有提供任何标志(第三个参数),因此您收到错误,它正试图将您的# somecomment解释为RewriteCond标志。

相关问题