【问题标题】:Porting htaccess rewrite rules to hiphop-php config将 htaccess 重写规则移植到 hiphop-php 配置
【发布时间】:2013-04-29 23:08:31
【问题描述】:

我有一个 CodeIgniter 项目,需要重写规则来导航控制器/视图等。我已经在 Ubuntu 12.04 上正确安装了 hiphop-php,它运行良好,包括他们网站上提供的示例 WordPress 安装和重写规则。

但是,我需要找出适用于 CodeIgniter index.php/controller 设置的正确重写规则,而我自己的运气并不好。

这是一个用于 WP 重写的示例 hiphop-php 配置文件:

http://www.hiphop-php.com/wp/

VirtualHost {
  * {
    Pattern = .*
    RewriteRules {
      dirindex {
        pattern = ^/(.*)/$
        to = $1/index.php
        qsa = true
      }
    }
  }
}

StaticFile {
  FilesMatch {
    * {
      pattern = .*\.(dll|exe)
      headers {
        * = Content-Disposition: attachment
      }
    }
  }

这里是 Apache 的示例 CodeIgniter mod_rewrite 文件:

http://www.farinspace.com/codeigniter-htaccess-file/

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /

    ### Canonicalize codeigniter URLs

    # If your default controller is something other than
    # "welcome" you should probably change this
    RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]

    # Removes trailing slashes (prevents SEO duplicate content issues)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ $1 [L,R=301]

    ###

    # Removes access to the system folder by users.
    # Additionally this will allow you to create a System.php controller,
    # previously this would not have been possible.
    # 'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

    # Checks to see if the user is attempting to access a valid file,
    # such as an image or css document, if this isn't true it sends the
    # request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

基本上,我需要重写的只是使用 CodeIgniter 的 index.php 控制器正确路由请求,这似乎是 apache 重写规则的最后一部分。其余的我可以在看到一些示例后一起破解。

非常感谢!

【问题讨论】:

    标签: php regex apache url-rewriting hiphop


    【解决方案1】:

    通常情况下,我通过自学找到了这一点,并从上面 Trip 的回答中朝着正确的方向努力。我写了如何使用 nginx 作为代理以及如何通过 nginx 推送 PHP 请求。

    http://www.kyleboddy.com/2013/05/02/facebooks-hiphop-engine-when-to-use-it-and-getting-it-to-work-with-codeigniter/

    【讨论】:

      【解决方案2】:

      我没有足够的声望对 SO 发表评论,但是...

      https://github.com/facebook/hiphop-php/blob/master/hphp/doc/options.compiled

      看起来没有办法在 HHPHP 配置中复制 -d 或 -f 标志,但选项的文档并不完全完整。如果可能的话,它必须看起来像这样:

          * {
            pattern = ^(.*)$
            to = /path/to/codeigniter/index.php/$1
            qsa = true
            conditions {
              -d {
                pattern = %{REQUEST_FILENAME}
                type = request
                negate = true
              }
              -f {
                pattern = %{REQUEST_FILENAME}
                type = request
                negate = true
              }
            }
          }
      

      您是否尝试过类似的方法?编辑:也许用 %{REQUEST_FILENAME} 块交换 -d 和 -f 文件标志。我可以把它倒过来。再说一次,文档不是很有启发性,我只是在吐痰。

      【讨论】:

      • 这不是确切的解决方案,但它引导我了解如何设置配置。我把 hhvm 通过一个 nginx 代理,很快就会写出来。
      • 删除了我之前的评论:我以为我有这个工作但错了。稍微挖掘一下源代码,显然不支持-d-f 标志。来源:github.com/facebook/hhvm/blob/…
      • Kyle,你能分享你的完整解决方案吗?
      【解决方案3】:

      使用 NGINX 作为 hiphop php 的前端。另外,您可以在提供静态文件时获得更好的性能。

      【讨论】:

      • 这基本上是我做的,但在我的赏金请求中,我说我想要具体的代码示例。一行注释没有多大帮助。
      猜你喜欢
      • 2011-02-13
      • 2018-10-06
      • 2011-10-22
      • 2014-04-30
      • 2015-09-24
      • 1970-01-01
      • 2020-01-10
      • 2014-10-30
      • 1970-01-01
      相关资源
      最近更新 更多