A
A
awe0072020-04-24 17:18:24
Nginx
awe007, 2020-04-24 17:18:24

How can I convert .htaccess to NGINX in a self-written engine?

Good afternoon. We were asked to transfer the site to another hosting. The site is on an old self-written engine that only works on php 5.4 and below. The site eventually migrated normally, but when you click on any link, the main page opens. I read that this is due to the fact that the rewrite rules that were under apache in .htaccess are not processed.

Since the engine is self-written, I did not find any ready-made rules for nginx. I tried several online converters, but the result is the same. Links don't work.

I myself am a system administrator and unfortunately I don’t have such experience :)
Here are the rules from .htaccess (the domain was just replaced)

RewriteCond %{HTTP_HOST} ^mydomain.ru [NC] 
RewriteRule ^(.*)$ http://www.mydomain.ru/$1 [L,R=301] 

RewriteRule ^404/{0,1}$ index.php?module=sitemap [L]

RewriteRule ^adm/{0,1}$ admin.php [L]
RewriteRule ^adm/([a-zA-Z0-9_-]+)/{0,1}$ admin.php?module=$1&%{QUERY_STRING} [L]
RewriteRule ^adm/([a-zA-Z0-9_-]+)/([0-9]+)/{0,1}$ admin.php?module=$1&page=$2&%{QUERY_STRING} [L]
RewriteRule ^adm/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/{0,1}$ admin.php?module=$1&p1=$2 [L]
RewriteRule ^adm/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/{0,1}$ admin.php?module=$1&p1=$2&p2=$3 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9_-]+).html/{0,1}$ index.php?module=static&p1=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/{0,1}$ index.php?module=$1 [L,QSA]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/{0,1}$ index.php?module=$1&p1=$2 [L,QSA]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/{0,1}$ index.php?module=$1&p1=$2&p2=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/{0,1}$ index.php?module=$1&p1=$2&p2=$3&p3=$4 [L]


The converter offers this option, but it also does not work.

if ($http_host ~* "^mydomain.ru"){
    rewrite ^(.*)$ http://www.mydomain.ru/$1 redirect;
  }
  rewrite "^/404/{0,1}$" /index.php?module=sitemap break;
  rewrite "^/adm/{0,1}$" /admin.php break;
  rewrite "^/adm/([a-zA-Z0-9_-]+)/{0,1}$" /admin.php?module=$1&$query_string break;
  rewrite "^/adm/([a-zA-Z0-9_-]+)/([0-9]+)/{0,1}$" /admin.php?module=$1&page=$2&$query_string break;
  rewrite "^/adm/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/{0,1}$" /admin.php?module=$1&p1=$2 break;
  rewrite "^/adm/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/{0,1}$" /admin.php?module=$1&p1=$2&p2=$3 break;
  if (!-e $request_filename){
    rewrite "^/([a-zA-Z0-9_-]+).html/{0,1}$" /index.php?module=static&p1=$1 break;
  }
  if (!-e $request_filename){
    rewrite "^/([a-zA-Z0-9_-]+)/{0,1}$" /index.php?module=$1 break;
  }
  rewrite "^/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/{0,1}$" /index.php?module=$1&p1=$2 break;
  rewrite "^/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/{0,1}$" /index.php?module=$1&p1=$2&p2=$3 break;
  rewrite "^/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/{0,1}$" /index.php?module=$1&p1=$2&p2=$3&p3=$4 break;


Is there any way to make these CNC links work?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexey Dmitriev, 2020-04-24
@awe007

Raise apache to localhost and proxy requests from nginx to it.
Or just install apache and remove nginx.

S
Sergey, 2020-04-24
@KingstonKMS

Study the logic of writing rewrite under nginx and write valid rules, or, as already advised, shove Apache with a gasket or just host a site on it

A
awe007, 2020-04-24
@awe007

Maybe someone can show an example of altering some one rule (one line) from htaccess ?

V
Viktor Taran, 2020-04-24
@shambler81

there is no point in bothering with 404.php
shove redirects and that's it.
so that the puff can do them easily and naturally,
and most importantly, you don’t clog htaccess until the url has arisen, no one tries to process the redirect.
Well, you can easily find redirects like www

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question