0

I need to translate some htaccess rules for the nginx server,

my htaccess was:

RewriteEngine On
RewriteBase /mysite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mysite/index.php/$1 [L]

SetOutputFilter DEFLATE

<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 1 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/x-javascript "access plus 216000 seconds"
</ifModule>

i've translated this part

RewriteEngine On
RewriteBase /mysite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mysite/index.php/$1 [L]

that looks like

if (!-f $request_filename){
  set $rule_0 1$rule_0;
}
if (!-d $request_filename){
  set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
  rewrite ^/(.*)$ /mysite/index.php/$1 last;
}

is it ok?

Then I need to translate the second part of the htaccess (showed above).

How can I translate that?

1 Answer 1

2
if (!-f $request_filename){
   set $rule_0 1$rule_0;
}
if (!-d $request_filename){
   set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
   rewrite ^/(.*)$ /bitfungus/index.php/$1 last;
}

is it ok?`

No, it's ugly. Nginx isn't apache, you should not use rewrites where you don't actually need them (in about 95% cases you don't need rewrites in nginx).

http://wiki.nginx.org/Pitfalls

Correct:

try_files $uri $uri/ /bitfungus/index.php$uri;
Sign up to request clarification or add additional context in comments.

2 Comments

ok thx, and what about the rest ..mod_gzip and mod_expires (from apache) ?
Read the documentation and write your own rules: nginx.org/en/docs/http/ngx_http_gzip_module.html and nginx.org/r/expires

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.