M
M
MaxUp2013-04-22 08:32:58
Nginx
MaxUp, 2013-04-22 08:32:58

Translation of .htaccess rules into nginx config

a question with the nginx config guru - I’m trying to transfer the .htaccess rules I’m used to to the nginx configs now, and I ran into several rules in which there are problems. I hope someone has already set up similar configs:

1. Redirecting all requests from index.php to url'e, except for POST requests

  RewriteCond %{REQUEST_METHOD} !=POST [NC]
  RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
  RewriteCond %{THE_REQUEST} !/folder_1/.*
  RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]


2. Remove the closing / for all URIs except those with an extension.
 RewriteCond %{REQUEST_URI} /$
  RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
  RewriteCond %{QUERY_STRING} !^(ACT=.*)$ [NC]
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.+)/$ $1 [L,R=301]


3. Block access to all hidden folders and files
  RewriteCond %{SCRIPT_FILENAME} -d [OR]
 RewriteCond %{SCRIPT_FILENAME} -f
 RewriteRule "(^|/)\." - [F]

update: my current solution

    location ~ /\. {
      deny all;
    }
 


4. Redirecting files like 'main.12345.css' -> 'main.css'
  RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]


Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
script88, 2013-04-22
@script88

Try online converter winginx.ru/htaccess

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question