在URI中出现index.php是非常丑陋的。我们可以使用Apache的虚拟主机功能和mod_rewrite规则,使URI变得更简洁。
在Apache的httpd.conf文件或其它可能的配置文件中,打开虚拟主机支持功能,并为你的Solar系统建立一个虚拟主机。虚拟主机应当指向SYSTEM/docroot目录,使该目录成为网站根目录。
NameVirtualHost *:80
<VirtualHost *:80>
ServerName subdomain.example.com
DocumentRoot SYSTEM/docroot
</VirtualHost>
在标准的Solar系统中,docroot目录下已经包含有.htaccess 文件,而且.htaccess文件也打开了mod_rewrite功能。文件包含类似下面这样的规则:
<IfModule rewrite_module>
# turn on rewriting
RewriteEngine On
# hint the Solar_Uri_Action class as to the base path
SetEnv SOLAR_URI_ACTION_PATH /
# turn empty requests into requests for "index.html",
# keeping the query string intact
RewriteRule ^$ index.html [QSA]
# for all files not found in the file system,
# reroute to "index.php" bootstrap script,
# keeping the query string intact.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
![]() | Note |
|---|---|
|
你需要在你的Apache配置文档的<Directory>部分,为SYSTEM目录设置AllowOverride All。 |
重启Apache之后,你应该可以使用新的虚拟主机浏览博客应用,但是此时,在URI中已经没有index.php了。例如:假设我们之前只能使用http://localhost/index.php/blog访问博客,现在你可以使用http://subdomain.example.com/blog访问了。
![]() | 编造一个域名 |
|---|---|
|
你通过在/etc/hosts文件中加入相关记录“编造”一个域名。例如,如果你在该文件中加入下面这行代码: 127.0.0.1 example.local 。。。你可以在浏览器中输入http://example.local,就好像它是一个真实的域名一样。这样的话,你就可以在你的虚拟主机中使用ServerName example.local设置域名。用这种方法,你可以添加任意数量的“假”域名。 |
![[Note]](images/note.png)

