简体   繁体   中英

convert nginx to htaccess(apache)

I got the following rewrite rules in Nginx in which im trying to convert for apache/.htaccess rules in which i was keep getting errors and didn't work out well, didnt find any online convertor from nginx to .htaccess only the opposite, Im hoping if anyone could help me out converting it.

This is my nginx rules:

if (!-d $request_filename){ 
 set $rule_0 1$rule_0; 
} 
if (!-f $request_filename){ 
 set $rule_0 2$rule_0; 
} 
if ($rule_0 = "21"){ 
 rewrite ^/(.*?)([^/]*)$ /$1index.php?$2 last; 
}

this is my .htaccess try:

<IfModule mod_rewrite.c>
RewriteEngine on
# Apache 2.4
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*?)([^/]*)$ $1index.php?$2 [QSA,PT,L]
RewriteEngine On
            RewriteBase /
        if (!-d $request_filename){ 
 set $rule_0 1$rule_0; 
} 
if (!-f $request_filename){ 
 set $rule_0 2$rule_0; 
} 
if ($rule_0 = "21"){ 
 rewrite ^/(.*?)([^/]*)$ /$1index.php?$2 last; 
}

ErrorDocument 404 /404.php

</IfModule>

but i keep on getting parse error whenever i try to do this, anyone have experience to sort this out?

You appear to have already done it, but for some reason you have also embedded the original Nginx directives in the middle (which will naturally result in a parse error).

So, the equivalent Apache/ .htaccess directives would seem to be the following only:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*?)([^/]*)$ $1index.php?$2 [QSA,L]

The PT flag is not required in a .htaccess context.

You do not need the <IfModule> wrapper, unless these directives are optional .


 if (;-d $request_filename){ set $rule_0 1$rule_0; }

However, the first set directive implies that the $rule_0 variable might have already been set earlier in the config?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM