Question

I have a CodeIgniter project that requires rewriting rules to navigate controllers/views and the like. I have correctly installed hiphop-php on Ubuntu 12.04 and it works perfectly, including with the sample WordPress installation and rewrite rules provided on their site.

However, I need to figure out the proper rewrite rules that will work with the CodeIgniter index.php/controller setup and I haven't had much luck myself.

Here is a sample hiphop-php config file for WP rewriting:

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

And here's a sample CodeIgniter mod_rewrite file for Apache:

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>

Basically all I need the rewriting to do is route the requests properly with the index.php controller of CodeIgniter, which seems to be what the last part of the apache rewrite rules do. The rest I can hack together after seeing some examples.

Thanks a bunch!

Was it helpful?

Solution

As is generally the case, I figured this one out via self-study and some pushing in the right direction from Trip's answer above. I wrote up how to use nginx as a proxy and how to push PHP requests through nginx.

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

OTHER TIPS

I don't have enough reputation to post a comment on SO, but...

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

It doesn't look like there's a way to duplicate the -d or -f flags in the HHPHP config, but the documentation of the options isn't exactly thorough. If it's possible, it has to look something like this:

    * {
      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
        }
      }
    }

Have you tried anything along these lines? EDIT: Maybe swap the -d and -f file flags with the %{REQUEST_FILENAME} piece. I could have that backwards. Again, the documentation isn't very illuminative, and I'm just spit-balling.

Use NGINX as frontend for hiphop php. As a plus You are get better performance for serve static files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top