bo-blog / bw

Bo-blog Wind Version
MIT License
95 stars 21 forks source link

网址绑定子目录后无法登陆(AJAX通讯错误) #31

Open Donny8611 opened 8 years ago

Donny8611 commented 8 years ago

使用.htaccess把网址绑定到子目录

RewriteCond %{HTTP_HOST} ^bw.xxxx.com$ RewriteCond %{REQUEST_URI} !^\/~bw\/ RewriteRule ^(.*)$ ~bw\/$1

假装不知道真实子目录名,用bw.xxxx.com安装好BW之后,可以访问,点登录提示"AJAX通讯错误"。

之前用BO-BLOG没出现过类似的问题,这个问题能通过BW本身解决吗?

bo-blog commented 8 years ago

嗯,因为程序输出的URL还是 http://xxxxx/~bw/,所以Ajax不正常(无法跨域)。 试着手动修改下 conf/info.php,第4行。

'siteURL' => 'http://bw.xxxxxx.com',

Donny8611 commented 8 years ago

嗯。这个问题确实有点奇葩,碰到了就想弄清楚。 因为我本来就是使用http://bw.xxxx.com 安装的。所以这里站点URL本来就是 'siteURL' => 'http://bw.xxxxx.com', 设置为'siteURL' => 'http://bw.xxxxx.com/~bw', 之后倒是可以登录了。只是这时候再点任何其他链接都会变成http://bw.xxxxx.com/~bw 这个地址。这样的话,等于是没有绑定子目录了。

bo-blog commented 8 years ago

2.0时代你是怎么设置后台根目录的啊?是自动获取么?

Donny8611 commented 8 years ago

不是啊。是设置的主域名

Donny8611 commented 8 years ago

有没有可能是我的htaccess有误?

bo-blog commented 8 years ago

可能这个rewrite和path_info有冲突。我会测试下。

bo-blog commented 8 years ago

看来是这个问题。虽然通过Apache Rewrite将 bw.xxxxx.com 绑定到了 www.xxxxx.com/~bw,但经我测试,PHP中获取的 $_SERVER['REQUEST_URI'] 仍然带有 ~bw 路径,这会导致 path_info 解析错误。 参考 http://stackoverflow.com/questions/5864810/request-uri-is-not-overridden-by-using-apache-rewriterule 暂时没有解决的方法。 为了照顾Nginx的通用性,下一版为会改写下程序,(不得不)兼容 index.php?xxx=xxx 这样的传参方式。到时候后台加个选项,你的问题应该可以解决。

_这次的教训是 pathinfo 兼容性问题很大,长痛不如短痛,下一版把ugly URL加回来。

Donny8611 commented 8 years ago

我觉得没必要吧。毕竟像我这样做的人在少数。为了个案让程序变得臃肿不是我想要的。

bo-blog commented 8 years ago

还是有必要的。Nginx不在少数。