Home  >  Q&A  >  body text

Help convert .htaccess rules to nginx rules

This rule is based on the rereite rules of the Blue Dolphin shopping guide program.

I want to convert the following .htaccess rules into nginx rules, please help...

<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]
</IfModule>
PHPzPHPz2712 days ago847

reply all(3)I'll reply

  • 怪我咯

    怪我咯2017-05-16 17:30:02

    A more accurate statement is: how to convert Apache's rewrite rules into nginx's. ——.htaccess is just a means and need not be mentioned too much, but it must be emphasized that the module involved is rewrite, because if it is another module, nginx may not have corresponding functions.

    Two ideas:

    1. Converter http://www.anilcetin.com/convert-apache-htaccess-to-nginx/
    2. This rewrite rule is very WordPress-like. You can check "wordpress nginx rewrite" and learn to modify it to suit you.

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 17:30:02

    The above rule means that if the file or folder corresponding to the URI does not exist, rewrite it. Apache's %{REQUEST_FILENAME} corresponds to $uri in nginx, so your above rules can be configured with the following try_files

    try_files    $uri $uri/  /index.php/$uri&$args;
    

    The function of try_files is to check whether the files exist in order and return the first found file or folder (a trailing slash indicates a folder). If all files or folders are not found, an internal reset will be performed. Directed to the last parameter.

    $args represents the parameters in the url.

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 17:30:02

    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 ^/(.*)$ /index.php/ last;
    }
    

    Apache rewrite rules converted to Nginx
    http://www.51ask.org/apache2n...

    reply
    0
  • Cancelreply