我刚刚开始尝试使用silex。我在遵循文档,我很困惑用哪种方式去。htaccess路径。背景资料:
- 我使用WAMP为我的开发web服务器,与
mod_rewrite
启用 - 我有Silex的"瘦身"副本解压缩并复制到c:'wamp'www' Silex '
- 我有一个例子hello world路由在c:'wamp'www'silex'web'index.php 我有一个。htaccess文件位于silex目录
.htaccess文件:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /silex/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
如果我去localhost/silex/web/hello/world,我得到一个工作的"hello world"页面,这是伟大的。
…但如果我去localhost/silex/hello/world,我得到silex错误:
找不到"GET/silex/hello/world"的路由
这个错误对我来说是有意义的…但这是否意味着"web/"必须包含在所有网站的url中?这对silex应用来说正常吗?
我想到了一些问题:
- .htaccess文件应该在——
silex/
或silex/web/
的哪个目录?如果我把它放在任何一个地方,会有什么问题吗? -
RewriteBase
应该去/silex
还是/silex/web
?(文档模糊地写着"/path/to/app";对我来说,这意味着/silex)
在/silex/.htaccess
中试试:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /silex/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ web/index.php [L]
</IfModule>
Silex示例假设将web
目录设置为虚拟主机的文档根目录。
每个应用程序应该有一个VHOST,例如silex.local
,文档根设置为c:'wamp'www'silex'web
。然后使用Silex站点的.htaccess
示例,并将其放入c:'wamp'www'silex'web'.htaccess
。
如果您没有DNS服务器,请使用本地hosts文件作为DNS:
注意:
确保apache的mod_rewrite是启用的
1:将此添加到hosts文件中:
linux /etc/hosts
windows c:'Windows'System32'drivers'etc'hosts
127.0.0.1 silex.local
2:创建一个新的虚拟主机(我使用apache):
linux ( Centos )
/etc/httpd/conf/httpd.conf
<VirtualHost *:80>
DocumentRoot /var/www/html/silex/
ServerName silex.local
</VirtualHost>
windows ( WAMP )
c:'wamp'bin'apache'Apache2.6'conf'httpd.conf
<VirtualHost *:80>
DocumentRoot C:/wamp/www/silex/
ServerName silex.local
</VirtualHost>
3:重启apache
4:在你的silex根文件夹创建。htaccess文件:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(.*)$ web/index.php [QSA,L]
</IfModule>