1. Please take a little time for this simple survey! Thank you for participating!
    Dismiss Notice
  2. Dear Pleskians, please read this carefully! New attachments and other rules Thank you!
    Dismiss Notice
  3. Dear Pleskians, I really hope that you will share your opinion in this Special topic for chatter about Plesk in the Clouds. Thank you!
    Dismiss Notice

Need help convert apache rewrite rules to nginx

Discussion in 'Plesk 11.x for Linux' started by Nerijuss, Nov 24, 2012.

  1. Nerijuss

    Nerijuss New Pleskian

    10
     
    Joined:
    Nov 24, 2012
    Messages:
    1
    Likes Received:
    0
    Hello,
    please help me convert apache rewrite rule to nginx:

    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^naujienos+ news.php/$1 [L]
    RewriteRule ^naujienos/p(.*)$ /news.php?pg=$1 [nc]
    RewriteRule ^naujienos/?$ /news.php [nc]
    RewriteRule ^naujienos?$ /news.php [nc]
     
  2. Alexey.Plotnitsky

    Alexey.Plotnitsky Regular Pleskian

    16
    55%
    Joined:
    Jan 19, 2012
    Messages:
    218
    Likes Received:
    3
    Hi Nerijuss,

    You can try this converter - http://winginx.ru/htaccess

    Then you will need to put nginx directives into custom nginx vhost config. However, please do not touch the config, created by Plesk Panel.
    You should add your custom nginx directives into Plesk nginx vhost template -
    /usr/local/psa/admin/conf/templates/default/domain/nginxDomainVirtualHost.php

    Then save it as a custom template -
    /usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php
     
  3. sgala.matteo

    sgala.matteo New Pleskian

    10
    35%
    Joined:
    Jun 5, 2012
    Messages:
    8
    Likes Received:
    0
    Can you be more detailed? for example:

    these are the default rewrite rules of a standard wordpress:

    Code:
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    translated with that tool it transform to:
    Code:
    location / {
    if (!-e $request_filename){
    rewrite ^(.*)$ /index.php break;
    }
    }
    
    but is not applicable in plesk vhost section as it complain about a duplicate "/" section.

    I tried/found also with the rule:
    Code:
    if (!-e $request_filename) { rewrite ^(.*)$ /index.php break; }
    
    and it's work...but it broke for example the access to webstatics, (seems that the section location ~ ^/plesk-stat/) is ignored/ovverridden by that rewrite rule.

    ideas?

    Thanks

    Matteo
     
  4. Alexey.Plotnitsky

    Alexey.Plotnitsky Regular Pleskian

    16
    55%
    Joined:
    Jan 19, 2012
    Messages:
    218
    Likes Received:
    3
    sgala.matteo,

    Since WordPress configuration could be a quite challenging task, I cannot give you advises for the rewrite rules itself.

    I suggest you to look into Nginx documentation:
    http://nginx.org/en/docs/http/ngx_http_rewrite_module.html
    http://nginx.org/en/docs/http/ngx_http_core_module.html#location

    As an idea - you can create a special location for Domain.tld/plesk-stat/ folder, without any rewrite rules processing.

    As another option, you can think of upgrade to Plesk 12. It has built WordPress toolkit that simplifies WP management: updates, plugins, themes:
    http://download1.parallels.com/Plesk/Doc/en-US/online/plesk-administrator-guide/73563.htm#
     
  5. sgala.matteo

    sgala.matteo New Pleskian

    10
    35%
    Joined:
    Jun 5, 2012
    Messages:
    8
    Likes Received:
    0
    Hi Alexey, I know where the documentation is located. The question of Nerijuss and mine was more technical and precise.

    I know that WP is provided also by Plesk automated installer but I'm not forced to use it and this is not related to this topic.

    The question is very precise: how to convert these apache rewrite rules to nginx rewrite rules as Plesk complain for / location already defined.

    The question it's very precise and related to Plesk, the NGINX documentation can't give us a solution but only workaround to bypass the Plesk error.

    Can you clarify how to write a correct rule that doesn't broke Plesk and it's in a "plesk way". I'm sure that a senjor engineer at Parallels can answer this.

    Thanks a lot,

    M.
     
  6. Alexey.Plotnitsky

    Alexey.Plotnitsky Regular Pleskian

    16
    55%
    Joined:
    Jan 19, 2012
    Messages:
    218
    Likes Received:
    3
    sgala.matteo,

    Switching to technical mode: correct, "location /" is already in nginx config, created by Plesk. Thus you cannot define it again.

    However, one do not need to specify the root location explicitly, the code below must work for all locations:
    if (!-e $request_filename){ rewrite ^(.*)$ /index.php break; }

    In order to alter nginx behavior for some location, one should add specific rules for this location (plesk-stat, as example).

     
Loading...