phalcon 访问IndexController 中只能访问indexAction方法,访问不了testAction
但是可以访问ArticleController里面的任意方法
看说是Apache 的rewrite问题,
但是我的.htaccess文件都是按照文档里面的。
两个.htaccess
第一个
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
<span">RewriteRule ((?s).*) public/$1 [L]
</IfModule>
public目录下面的.htaccess中
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
访问路由 localhost/index/test访问不到,但是localhost/index.php?_url=/index/test可以访问得到
解决方法:
直接打印 $_request,发现当路径为 localhost/index/test 的时候,没有_url参数,判断是url重新没成功。将 RewriteCond %{REQUEST_FILENAME} !-f 这行去掉,发现_url 的值是 index.php/test
也就是说apache没有将index/test 看成一个整体,分开请求了,先请求index再请求test,当index不存在时,直接去找index.php,index.html,此时index匹配成功重写取消,而index下的test没有匹配成功,重写后就成了index.php/test了。那么apache为什么不是把index/test看成一个整体,而是分开去处理呢?
怀疑是因为httpd.conf中打开了允许列出目录的功能 mod_autoindex;并设置了Options Indexes允许目录浏览,受目录浏览影响导致重写问题,
取消掉Options 的其他参数,仅保留FollowSymLinks参数,重启apache后,index/test 可以正常访问了
难道真是目录浏览功能的问题?
Options +Indexes +Includes +FollowSymLinks +MultiViews
配置中一共有四个参数,挨个试,最后发现是受MultiViews参数影响。。。但是具体为什么就不清楚了,
ps:出现该问题的工具是wampserver 3.0.6 64bit 版本,32bit版本的没出现该问题,老版的apache也没出过现该问题,猜测可能是apache版本升级进行了什么调整导致的,具体原因再论。
2018-11-28 更新
今天看到一篇文章,标题为: apache的MultiViews的问题
文章来源:https://blog.csdn.net/u014359108/article/details/70859651
该博文介绍了:
MultiViews的作用是当访问到目录中不存在的对象时,
如访问”http://localhost/test/target”,
则apache会寻找该目录下的所有target.*文件.
如果test目录下存在target.jpg文件,
则会把这个文件返回给客户,
而不是返回出错信息.
再分析一下我们现在面对的实例.由于MultiViews的特性,
当访问“http://servername/Index/index”时.
由于根目录下存在index.php文件
所以上面的访问会变成这样:
“http://servername/Index.php/index”
到这里,就清楚为什么httpd.conf中有MultiViews
配置是
Options +FollowSymLinks +MultiViews
phalcon 访问indexController 的方法是就只能访问indexAction()了