Welcome! Log In Create A New Profile

Advanced

Rewrite rules / apache > nginx (downloads php files)

Posted by StimpMedia 
Rewrite rules / apache > nginx (downloads php files)
April 29, 2013 04:25AM
Dear people,

I'm stuck with a third party designed website that needs to run for a brief time on nginx (to improve the speed). There is a new site in development but for the time being it has to work. The current Apache rewrite config below:

---
RewriteEngine on

RewriteRule ^([A-Z]{2,3})/rss/(.*)/$ index.php?changelang=$1&p=rss&rsssub=$2 [L]
RewriteRule ^rss/(.*)/$ index.php?p=rss&rsssub=$1 [L]

#check if file exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/scripts/(.*)$ scripts/$2 [NC,L]
RewriteRule ^(.*)/cats/(.*)$ cats/$2 [NC,L]
RewriteRule ^(.*)/cms/(.*)$ cms/$2 [NC,L]
RewriteRule ^(.*)/images/(.*)$ images/$2 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^images/(.*)$ images/cp/geen_foto\.gif [NC,L]
RewriteRule ^(.*)/css/(.*)$ css/$2 [NC,L]
RewriteRule ^([A-Z]{2,3})/index\.php?(.*)$ index.php?changelang=$1&pid=$2 [QSA,L]
RewriteRule ^index\.php?(.*)$ index.php?pid=$1 [QSA,L]
RewriteRule ^([A-Z]{2,3})/$ index.php?changelang=$1 [L]
RewriteRule ^([A-Z]{2,3})/(.*)\.html$ index.php?changelang=$1&userurl=$2\.html [L]
RewriteRule ^(.*)\.html$ index.php?userurl=$1\.html [L]
RewriteRule ^([A-Z]{2,3})/(.*)/$ index.php?changelang=$1&userurl=$2 [L]
RewriteRule ^(.*)/$ index.php?userurl=$1 [L]
RewriteRule ^(.*)/(.*)\.html$ index.php [L]
---


When I convert the rules I get:

----
location / {
rewrite "^/([A-Z]{2,3})/rss/(.*)/$" /index.php?changelang=$1&p=rss&rsssub=$2 break;
if (!-e $request_filename){
rewrite ^/(.*)/scripts/(.*)$ /scripts/$2 break;
}
rewrite ^/(.*)/cats/(.*)$ /cats/$2 break;
rewrite ^/(.*)/cms/(.*)$ /cms/$2 break;
rewrite ^/(.*)/images/(.*)$ /images/$2 break;
if (!-e $request_filename){
rewrite ^/images/(.*)$ /images/cp/geen_foto\.gif break;
}
rewrite ^/(.*)/css/(.*)$ /css/$2 break;
rewrite "^/([A-Z]{2,3})/index\.php?(.*)$" /index.php?changelang=$1&pid=$2 break;
rewrite "^/([A-Z]{2,3})/$" /index.php?changelang=$1 break;
rewrite "^/([A-Z]{2,3})/(.*)\.html$" /index.php?changelang=$1&userurl=$2\.html break;
rewrite ^/(.*)\.html$ /index.php?userurl=$1\.html break;
rewrite "^/([A-Z]{2,3})/(.*)/$" /index.php?changelang=$1&userurl=$2 break;
rewrite ^/(.*)/$ /index.php?userurl=$1 break;
rewrite ^/(.*)/(.*)\.html$ /index.php break;
}

location /rss {
rewrite ^/rss/(.*)/$ /index.php?p=rss&rsssub=$1 break;
}

location /index {
rewrite ^/index\.php?(.*)$ /index.php?pid=$1 break;
}
----

This results in non working rewrite rules and the PHP files are just being downloaded. I know If statements are not done and try_files must be used but I miss the expertise to correct this errors. Is there someone who can help me out with this?
Re: Rewrite rules / apache > nginx (downloads php files)
May 05, 2013 04:49PM
Sure, for the money.

Best regards,

Andrejs
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 265
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready