Convert rules form .htaccess

Discussion in 'Nginx' started by singularity79, Oct 20, 2015.

  1. #1
    Good day,

    I've just installed a simple url shortener script on my website, unfortunately the author is not able to give me advice for Nginx since he wrote the script with Apache and mod_rewrite in his mind, so many url rewrites are not correctly interpreted.

    Also when I click on alink, the browser downloads the php page...

    I've tried to use the online .htaccess to Nginx converters, but the resulting code, is not working.

    This is the orginal .htacces file

    RewriteEngine on
    RewriteCond %{request_filename} -f
    RewriteRule ^(.*) $1 [L]
    RewriteRule ^(([^/]*)+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3 [L]
    Code (ApacheConf):


    nginx code from online converter

    location / {
    if (-e $request_filename){
    rewrite ^/(.*) /$1 break;
    }
    rewrite "^/(([^/]*)+)(/([^/]{0,32})(/.+)?)?$" /index.php?a=$1&q=$3 break;
    }
    Code (markup):




    Nginx vhost config file (inside /etc/nginx/sites-enabled)

    server {
    listen *:80;
    
    
    server_name tuolink.it *.tuolink.it;
    
    root /var/www/tuolink.it/web;
    
    
    index index.html index.htm index.php index.cgi index.pl index.xhtml;
    
    error_log /var/log/ispconfig/httpd/tuolink.it/error.log;
    access_log /var/log/ispconfig/httpd/tuolink.it/access.log combined;
    
    
    location @php {
    try_files $uri =404;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/var/lib/php5-fpm/web5.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
    }
    
    location /cgi-bin/ {
    try_files $uri =404;
    include /etc/nginx/fastcgi_params;
    root /var/www/clients/client1/web5;
    gzip off;
    fastcgi_pass unix:/var/run/fcgiwrap.socket;
    fastcgi_index index.cgi;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
    }
    
    }
    
    Code (markup):

    Any suggestion about the correct converted code for Nginx?

    Many thanks
     
    singularity79, Oct 20, 2015 IP
  2. wissam

    wissam Well-Known Member

    Messages:
    2,289
    Likes Received:
    78
    Best Answers:
    1
    Trophy Points:
    185
    #2
    Don't use that converter I fell into the same problem use this instead:
    www.anilcetin.com
    saved my life, I wish there was an offline version in case that site shut down, to be honest I am not into learning nginx rules right now lol
     
    wissam, Mar 4, 2016 IP