Nginx directives to Apache migration

Problems with the Linux version of XAMPP, questions, comments, and anything related.

Nginx directives to Apache migration

Postby mardif » 15. June 2018 11:46

Hi at all,
I've a client project made with Nginx as Web Application. Now I need to convert this Nginx directives to Apache, but there are some directives that doesn't works.

Nginx directive (it works):
Code: Select all
location ~ /(.*?_trk_).*\.(jpg|jpeg|gif|png|svg|pdf|zip|woff|woff2|JPG|JPEG|GIF|PNG|SVG|PDF|ZIP|WOFF|WOFF2) {
 expires 1d;
 rewrite ".*_trk_([^_]*)_([^_]*)_([^_]*)_(.*)" -0000000$3#$3#$4#/img/trk_images/$1/$2/$3/$4;
 rewrite "-0*?((\d{2})(\d{2})(\d{2})(\d{2}))#([^#]*)#([^#]*)#([^#]*)" $uri break;
 try_files /imgn/csm/$2/$3/$4/$5/$6/$7 /img/csm/$2/$3/$4/$5/$6/$7 @notfound-csm;
}


Apache 2.4 (it doesn't works):
Code: Select all
RewriteEngine on
RewriteCond %{REQUEST_URI} /(.*?_trk_).*\.(jpg|jpeg|gif|png|svg|pdf|zip|woff|woff2|JPG|JPEG|GIF|PNG|SVG|PDF|ZIP|WOFF|WOFF2)
RewriteRule ^.*_trk_([^_]*)_([^_]*)_([^_]*)_(.*)$ -0000000$3#$3#$4#/img/trk_images/$1/$2/$3/$4
RewriteRule ^-0*?((\d{2})(\d{2})(\d{2})(\d{2}))#([^#]*)#([^#]*)#([^#]*)$ /imgn/csm/$2/$3/$4/$5/$6/$7


This is an example of the image uri: http://images.domain.dev/_trk_dealer_37556_805784_b_805784_25203968.jpg

Images are stored inside this pattern path:

/imgn/csm/01/02/14/56/1021456/b_805784_25203968.jpg

Apache reply me with 404... Why?

Can someone helpme to translate it?

Thanks in advance
mardif
 
Posts: 2
Joined: 15. June 2018 09:55
XAMPP version: 7.1.7
Operating System: Centos 7

Re: Nginx directives to Apache migration

Postby Nobbie » 15. June 2018 22:42

instead of a pointless pattern, show us a concrete example of an URL and the matching path so that we can see exactly how to translate the URL.
Nobbie
 
Posts: 10289
Joined: 09. March 2008 13:04

Re: Nginx directives to Apache migration

Postby mardif » 19. June 2018 11:02

Ok Nobbie, you right.

I would like to find a way to link the current img URL:

Code: Select all
http://images.domain.dev/_trk_dealer_37556_805784_b_fgh54545y25203968.jpg


to this server PATH

Code: Select all
/imgn/csm/00/80/57/84/805784/b_fgh54545y25203968.jpg


This is folders structure:
Code: Select all
-imgn is static
-csm is static
-00 is the first 2 digits of 8 for the ads id:  805784 (if the id has 8 digits, it changed ex: in 19805784 the first part will be 19 and not 00)
-80 is the second 2 digits of 8 for the ads id:  805784
-57 is the third part of 2 digits of 8 for the ads id:  805784
-84 is the fourth part of 2 digits of 8 for the ads id:  805784
-805784 is the id in full
-b_fgh54545y25203968.jpg is the filename


Hope I explained myself better.

Thank you
mardif
 
Posts: 2
Joined: 15. June 2018 09:55
XAMPP version: 7.1.7
Operating System: Centos 7

Re: Nginx directives to Apache migration

Postby Nobbie » 21. June 2018 10:52

Your description does not match to the RewriteRules:

Code: Select all
RewriteRule ^.*_trk_([^_]*)_([^_]*)_([^_]*)_(.*)$ -0000000$3#$3#$4#/img/trk_images/$1/$2/$3/$4
RewriteRule ^-0*?((\d{2})(\d{2})(\d{2})(\d{2}))#([^#]*)#([^#]*)#([^#]*)$ /imgn/csm/$2/$3/$4/$5/$6/$7


1) What is the idea of the first RewriteRule?
2) The second RewriteRule fairly meats your description, but not quite at all. As you can see, in that Rule the incoming URL should contain tokens beginning with "#", for example, this URL would match:

http://images.domain.dev/25203968#abc#defg#123.jpg

As you can see, this differs from your URL in your description.
Nobbie
 
Posts: 10289
Joined: 09. March 2008 13:04

Re: Nginx directives to Apache migration

Postby Nobbie » 21. June 2018 11:20

I have gone deeper into that, i think the RewriteRules are OK! But i also think, that you must CHAIN them (i have no experience with that, but it looks as it is what you are looking for). Try this:

Code: Select all
RewriteRule ^.*_trk_([^_]*)_([^_]*)_([^_]*)_(.*)$ -0000000$3#$3#$4#/img/trk_images/$1/$2/$3/$4  [C]
RewriteRule ^-0*?((\d{2})(\d{2})(\d{2})(\d{2}))#([^#]*)#([^#]*)#([^#]*)$ /imgn/csm/$2/$3/$4/$5/$6/$7


The most important change is the "[C]" in the end of the first RewriteRule, this tells the RewriteEngine to CHAIN this Rules. Give it a try, i cannot test it due to missing examples.
Nobbie
 
Posts: 10289
Joined: 09. March 2008 13:04


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 4 guests