Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Porting htaccess rewrite rules to hiphop-php config

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!

like image 987
Michael B Avatar asked Feb 16 '23 16:02

Michael B


2 Answers

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/

like image 175
Michael B Avatar answered Feb 24 '23 10:02

Michael B


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.

like image 42
Trip Avatar answered Feb 24 '23 11:02

Trip