在没有vhost和Apache的情况下使用Silex

时间:2012-11-01 12:09:07

标签: symfony apache2 silex

我正在Github上使用Fabien的骨架建立我的第一个Silex项目: https://github.com/fabpot/Silex-Skeleton

由于某些原因,我无法为此项目创建vhost,所以silex项目会保留在子目录中。

我的目录结构如下所示:

/my/example.com/htdocs/myapp/
      ../src/app.php
      ../cache
      ../config
      ../templates
      ../vendor
      ../web/index.php 

我想通过网址访问我的应用: http://example.com/myapp/hello/Fabien/

我在htdocs / myapp

中创建了一个.htaccess文件
<IfModule mod_rewrite.c>
   Options -MultiViews
   RewriteEngine On
   RewriteBase /myapp
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^ web/index.php [L]
</IfModule> 

现在我有网址喜欢 http://example.com/myapp/index.php/hello/Fabien/

如何摆脱index.php?

2 个答案:

答案 0 :(得分:1)

您应该将RewriteBase指令更改为/myapp/web

RewriteBase /myapp/web

答案 1 :(得分:0)

仅供参考:您可以使用php内置的Web服务器运行Silex,根本没有Apache。在本地开发环境中快速启动黑客/原型设计非常方便。 Fabien的骨架的composer.json包含启动本地Web服务器的说明。您可以通过在项目目录中执行composer run来完成此操作。

这种方法的局限性在于作曲家将在300秒内停止服务器。为避免这种情况,您应该直接执行以下命令:php -S localhost:8888 -t web web/index_dev.php。您好的页面将在http://localhost:8888/hello/Fabien/处提供。