mediocre
mediocre

Reputation: 564

Converting apache rewrite rules (.htaccess) to nginx

Background:

I want to setup Bugify on my Ubuntu Server running nginx. I followed the instructions, installed the dependencies and the installation was successful. Once I enter my licence key and click on "Install Bugify" it's redirecting to http://dev.mysite.com/login?new and the only thing I'm seeing is 404 Not Found.

I know that nginx isn't officially supported but according to the support forum it should be possible to run it.

Question:

There's a .htaccess file with rewrite rules in the webapp's public directory and I guess the problem causing the 404 error is that nginx isn't able to work with the .htaccess file, so I'll have to convert the rewrite rules to the nginx syntax.

I'm not really familiar with apache's rewrite rules so I'd need some help figuring this out.

The content of the .htaccess file is:

# Rewriting
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

I was using this tool to convert the rules but it's having some troubles with the - flags.

#ignored: "-" thing used or unknown variable in regex/rew

Thanks in advance!

Upvotes: 0

Views: 1893

Answers (1)

Robert Kern
Robert Kern

Reputation: 329

Bugify uses the Zend Framework, so the rewrite rules for ZF should work for Bugify also. I have copied the suggested nginx config below from http://wiki.nginx.org/Zend_Framework

server {
  listen 80;
  server_name www.example.com;
  root /var/www/www.example.com/myapplication;
  index  index.html index.htm index.php;

  location / {
    # This is cool because no php is touched for static content
    try_files $uri $uri/ /index.php;
  }

  location ~ \.php$ {
    fastcgi_pass      unix:/usr/local/zend/tmp/php-fastcgi.socket;
    fastcgi_index    index.php;
    fastcgi_param   SCRIPT_FILENAME /var/www/www.example.com/myapplication$fastcgi_script_name;
    include               fastcgi_params;
  }
}

Upvotes: 1

Related Questions