YA Converting .htaccess to nginx, I can't get it to work!

otherjohn nginx-forum at nginx.us
Tue Feb 5 03:23:46 UTC 2013

Hi all,
I am trying to convert this htaccess file to nginx config and it is not
Here is my .htaccess

<IfModule mod_headers.c>
        Header unset ETag
        FileETag None
        <FilesMatch "(?i)^.*\.(ico|flv|jpg|jpeg|png|gif|js|css)$">
                Header unset Last-Modified
                Header set Expires "Fri, 21 Dec 2020 00:00:00 GMT"
                Header set Cache-Control "public, no-transform"

<IfModule mod_rewrite.c>
        RewriteEngine   On
        RewriteCond     %{QUERY_STRING} ^$
        RewriteRule     ^((.)?)$        index.php?p=home [L]

        RewriteCond %{REQUEST_FILENAME} -f
        RewriteRule ^(.*)$ $1 [QSA,L]

        RewriteCond     $1
        RewriteRule     ^(.+)$ index.php?url=$1&%{QUERY_STRING} [L]

<IfModule mod_deflate.c>
        <FilesMatch "\.(js|css|ico|flv|jpg|jpeg|png|gif)$">
                SetOutputFilter DEFLATE

and here is my config. I can get it to somewhat work if I only use one of
the following lines but then the rest is broke!

location / {
  if ($query_string ~ "^$"){
    rewrite ^/((.)?)$ /index.php?p=home break;
  if (-e $request_filename){
    rewrite ^(.*)$ /$1 break;
  rewrite ^(.+)$ /index.php?url=$1&$query_string break;
location ~ \.php$ {
                        try_files $uri =404;
                        fastcgi_pass unix:/tmp/php5-fpm.sock;
                        fastcgi_index index.php;
                        include /etc/nginx/fastcgi_params;


Not to mention that I hate using the if else clauses in my nginx config
because I think I read where it is poor for performance.

Can someone give me a hand here. I have been working on this for hours
without any luck.

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,235905,235905#msg-235905

More information about the nginx mailing list