Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I just changed to NGINX from Apache and I am using Zencart with Ultimate SEO for friendly urls I have tried to convert my .htaccess rules for NGINX but I get "No Input file specified" or a 404 error. My original .htaccess is as follows:

 ErrorDocument 404 /404.html


 Options +FollowSymLinks
 RewriteEngine On




 # From Ultimate SEO URLs
 RewriteRule ^(.*)-p-(.*).html$ index\.php?main_page=product_info&products_id=$2&%{QUERY_STRING} [L]
 RewriteRule ^(.*)-c-(.*).html$ index\.php?main_page=index&cPath=$2&%{QUERY_STRING} [L]
 RewriteRule ^(.*)-m-([0-9]+).html$ index\.php?main_page=index&manufacturers_id=$2&%{QUERY_STRING} [L]
 RewriteRule ^(.*)-pi-([0-9]+).html$ index\.php?main_page=popup_image&pID=$2&%{QUERY_STRING} [L]
 RewriteRule ^(.*)-pr-([0-9]+).html$ index\.php?main_page=product_reviews&products_id=$2&%{QUERY_STRING} [L]
 RewriteRule ^(.*)-pri-([0-9]+).html$ index\.php?main_page=product_reviews_info&products_id=$2&%{QUERY_STRING} [L]
 RewriteRule ^(.*)-ezp-([0-9]+).html$ index\.php?main_page=page&id=$2&%{QUERY_STRING} [L]



 # All other pages
 # Don't rewrite real files or directories
 RewriteCond %{REQUEST_FILENAME} !-f [NC] 
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*).html$ index\.php?main_page=$1&%{QUERY_STRING} [L]

And this us what I have added in to the virtual.conf in NGINX

 rewrite ^/(.*)-p-(.*).html$ /index\.php?main_page=product_info&products_id=$2&$args last;
 rewrite ^/(.*)-c-(.*).html$ /index\.php?main_page=index&cPath=$2&$args last;
 rewrite ^/(.*)-m-([0-9]+).html$ /index\.php?main_page=index&manufacturers_id=$2&$args last;
 rewrite ^/(.*)-pi-([0-9]+).html$ /index\.php?main_page=popup_image&pID=$2&$args last;
 rewrite ^/(.*)-pr-([0-9]+).html$ /index\.php?main_page=product_reviews&products_id=$2&$args last;
 rewrite ^/(.*)-pri-([0-9]+).html$ /index\.php?main_page=product_reviews_info&products_id=$2&$args last;
 rewrite ^/(.*)-ezp-([0-9]+).html$ /index\.php?main_page=page&id=$2&$args last;
 if (!-f $request_filename){
 set $rule_7 1$rule_7;
}
if (!-d $request_filename){
set $rule_7 2$rule_7;
}
if ($rule_7 = "21"){
rewrite ^/(.*).html$ /index\.php?main_page=$1&$args last;
}

    }

Any ideas what I have done wrong?

Peter

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

Without the whole server definition it's hard to tell what's happening because location directives are processed in a specific order and your php configuration may be causing an issue.

Anyway, the most obvious problem is in the index.php rewrites. Don't slash escape the period. (index\.php should be index.php).

As for the last part, it can be simplified:

if (-f $request_filename) {
  break;
}
if (!-d $request_filename) {
  rewrite ^/(.*).html$ /index.php?main_page=$1&$args last;
}
share|improve this answer
    
It works perfectly now thanks for your help! I changed to NGINX because I was getting DDOS now my server is coping! –  Peter Aug 1 '11 at 18:05
add comment

Well, you can start by replacing those hideous compound if statements with try_files:

try_files $uri $uri/ /index.php?main_page=$uri&$args;

Removing the escapes on the periods in the replacement part of the rewrite directives wouldn't hurt, either; I don't know if nginx handles them as you expect, but they're certainly not doing you any good.

Apart from that, nothing looks particularly out of place, so fix up those things and check your error log; 404s log what they failed to find so you can see what you've done wrong.

share|improve this answer
    
you can't replace the if statements because the of the regex rewrite. –  h0tw1r3 Aug 1 '11 at 9:14
    
[citation needed] I've got try_files and rewrites together, and the nginx manual shows them working together, too. –  womble Aug 1 '11 at 9:27
    
I know they work together, my point is that what you propose does not achieve the same result as the rules in the original question. Your suggestion is a "best practice", but may not be applicable to this specific situation. –  h0tw1r3 Aug 1 '11 at 9:53
    
I don't see why not. I just tried it and it seems to work fine (well, FSVO since I don't have the site available, but it loads test files OK). –  womble Aug 1 '11 at 10:25
    
Because the rewrite is specific to (.*).html, your replacement catches everything and does not drop the .html. I'm sure test files work, but this is an existing application that expects stuff in a very specific way. –  h0tw1r3 Aug 1 '11 at 15:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.