Convert Nginx redirect rule to . htaccess

Asked

Viewed 515 times

-1

I have the following rule on an Nginx server in production:

server {
    server_name meusite.srv.br;
    rewrite ^(.*) http://www.meusite.srv.br$1 permanent;

}

server { server_name www.meusite.srv.br; access_log /home/pastaprojeto/Prod/Nginx/logs/access.log; error_log /home/pastaprojeto/Prod/Nginx/logs/error.log; root /home/pastaprojeto/Prod/public_html;

gzip  on;
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_proxied any;
    gzip_types image/png image/gif image/jpeg image/x-icon text/css text/cache-manifest font/truetype font/opentype font/woff application/vnd.ms-fontobject application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml$

    gzip_buffers 16 8k;

    # Disable gzip for certain browsers.
    gzip_disable msie6;

    location / {
            index       index.html      index.php;
    try_files $uri $uri/ @rewrite_prod;
    }

location @rewrite_prod {

            rewrite ^/ajax/(.*)?$  /app/controller/ajax/$1.caj.php last;
            rewrite ^/data/(.*)?$  /app/controller/data/$1.data.php last;

            rewrite ^/([^/]*)/favicon.ico$  /favicon.ico last;

            rewrite  ^/([^/]*)(/([^/]*)/?)?(/([^/]*)/?)?$ /index.php?page=$1&action=$3&value=$5  last;
    }

location ~*\.(eot|otf|svg|ttf|woff)$ {
            add_header Access-Control-Allow-Origin *;
    }

    location ~ /(.+)\.(inc.php|class.php|add.php|edit.php|search.php|ws.php|auto.php|cfg.php|cfc.php|cfg.xml)$ {
             deny all;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_read_timeout 300;
    fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
    fastcgi_pass unix:/var/run/php5-fpm.sock;                                                                                                                                                  
        fastcgi_index index.php;                                                                                                                                                            
        fastcgi_param SCRIPT_FILENAME /home/pastaprojeto/prod/public_html$fastcgi_script_name;                                                                                                              
    }                                                                                                                                                                                       

}

I don’t understand ER and I need this rule in a . htaccess file for apache. I tried a few ways but I couldn’t.

How can I transcribe this?

1 answer

0

Try the following settings:

RewriteEngine On
RewriteRule ^/ajax/(.*)?$ /app/controller/ajax/$1.caj.php
RewriteRule ^/data/(.*)?$ /app/controller/data/$1.data.php
RewriteRule ^/([^/]*)/favicon.ico$ /favicon.ico
RewriteRule ^/([^/]*)(/([^/]*)/?)?(/([^/]*)/?)?$ /index.php?page=$1&action=$3&value=$5

Don’t forget to enable Apache rewrite module. :)

  • It didn’t work ): I put the Nginx code all over.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.