2013-03-17 124 views
4

我为我的应用程序的路由目的使用Silex“微型框架”。 我目前被困在如何用.htaccess重写URL。Silex路由.htaccess webroot

标准Silex的网址:localhost/myapp/web/index.php/hello/name

我希望它看起来像:localhost/myapp/hello/name

用下面的.htaccess代码,我能够省略/index.php/部分。但我仍然需要使用/web/部分。

RewriteEngine On 
RewriteCond %{THE_REQUEST} /myapp/web/index.php/ 
RewriteRule ^/myapp/web/index.php/(.*) /myapp/$1 [R=301,L] 
RewriteCond %{REQUEST_URI} !/myapp/web/index.php/ 
RewriteRule ^(.*)$ /myapp/web/index.php/$1 [L] 

有什么建议吗? 谢谢!

+0

我陷入了同样的问题。似乎没有任何工作。 – Kandinski 2013-12-15 05:46:04

回答

0

像这样的东西应该做的伎俩:

RewriteEngine On 
RewriteBase/

RewriteRule ^myapp/web/index.php/ /myapp/     [R=301,L] 
RewriteRule ^myapp/    /myapp/web/index.php/ [L] 
1

来源:http://silex.sensiolabs.org/doc/web_servers.html

<IfModule mod_rewrite.c> 
    Options -MultiViews  
    RewriteEngine On 
    RewriteBase /web 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule^index.php [QSA,L] 
</IfModule> 

权将设置您DocumentRoot/path/to/your/app/web

0

我有一个类似的问题,与解决以下

<IfModule mod_rewrite.c> 
Options -MultiViews 
RewriteEngine On 
RewriteBase /web 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)? index.php/$1 [QSA,L] 
RewriteRule ^/?$ /web/ [R=301] 
</IfModule> 
2

我现在已经面临着同样的问题,解决办法是改变的.htaccess内容:

FallbackResource /index.php 

所以在你的情况将是

FallbackResource /web/index.php 

这对我有用,我希望有人会觉得它有用。

+0

那么,只适用于Apache> = 2.2.16 – mTorres 2015-11-23 11:42:17