【发布时间】:2011-07-06 09:33:44
【问题描述】:
我正在尝试将 http://localhost/website 转换为 http://website.loc,但我无法做到这一点。这是我能做的:
我通过将 127.0.0.1 localhost 更改为 127.0.0.1 localhost website.loc 来编辑 /etc/hosts(我在 Ubuntu 上)并保存了更改
我在/etc/apache2/sites-available 内创建了一个名为website 的新文件,内容如下:
<virtualhost website.loc>
ServerName website.loc
DocumentRoot /home/myuser/projects/website/
<directory /home/myuser/projects/website/>
AllowOverride all
Options Indexes FollowSymLinks MultiViews
Order allow,deny
allow from all
</directory>
</virtualhost>
我创建了一个指向启用站点的软链接来启用此功能。之后,我重新启动了 Apache。 顺便说一句,我使用的是 Yii 框架,对 / 的任何请求都重定向到 /index.php,因此查询中不需要 index.php。
因此,当我将 website.loc/ 写入 chrome 时,它会将我移动到 http://website.loc/site/login(登录索引页面,即使我以 localhost 身份登录也几乎可以预期,因为站点 url “更改”为 website.loc/ 。 loc,所以 cookie 不共享),但内容是:
Not Found
The requested URL /website/index.php was not found on this server.
Apache/2.2.16 (Ubuntu) Server at website.loc Port 80
我做错了吗?在此先感谢各位朋友
编辑:这都是关于 /home/myuser/projects/website 中的 .htaccess 的。它的 RewriteBase 指向 /website。将其更改为 / 它就像魅力一样。感谢@Chux 提醒我检查 .htaccess!
【问题讨论】: