【问题标题】:Silex routing .htaccess webrootSilex 路由 .htaccess webroot
【发布时间】:2013-03-05 20:39:32
【问题描述】:

我正在使用 Silex“微框架”来为我的应用程序进行路由。 我目前被困在如何用 .htaccess 重写 url。

标准 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]

有什么建议吗? 谢谢!

【问题讨论】:

  • 我遇到了同样的问题。似乎没有任何效果。

标签: php .htaccess routing silex


【解决方案1】:

我现在遇到了同样的问题,解决方案是将 .htaccess 内容更改为:

FallbackResource /index.php

所以你的情况是

FallbackResource /web/index.php

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

【讨论】:

  • 好吧,仅适用于 Apache >=2.2.16
【解决方案2】:

发件人: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

【讨论】:

    【解决方案3】:

    这样的事情应该可以解决问题:

    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^myapp/web/index.php/  /myapp/                 [R=301,L]
    RewriteRule ^myapp/                /myapp/web/index.php/   [L]
    

    【讨论】:

      【解决方案4】:

      我也遇到过类似的问题,用下面的方法解决了

      <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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-20
        • 2023-04-01
        • 2015-02-14
        • 1970-01-01
        相关资源
        最近更新 更多