Error 500: .htaccess RewriteCond: bad flag delimiters

混江龙づ霸主 提交于 2019-12-14 04:01:44

问题


I've noticed many questions about that problem, but in my case the htaccess is very simple:

<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 weeks about now I haven't problem with that rewritebase, but now I can't start my simple RestAPI :/

Any suggestions why this doesn't work?


回答1:


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

The 500 Error is the result of your line-end comments. Apache does not actually support line-end comments.

Lines that begin with the hash character "#" are considered comments, and are ignored. Comments may not be included on the same line as a configuration directive.

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

Sometimes line-end comments appear to work because of a "fluke". If you supply all the arguments to the directive then anything trailing on the line is ignored. But in this case you have not supplied any flags (the 3rd argument), so you get the error, it is trying to interpret your # somecomment as RewriteCond flags.




回答2:


It seems as if your comment on the lines

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

Are not interpreted as comments but as parameters to RewriteCond. Remove those (or move them on the line above RewriteCond).

IIRC comments are only supported at the beginning of a line in Apache httpd.



来源:https://stackoverflow.com/questions/31770294/error-500-htaccess-rewritecond-bad-flag-delimiters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!