Apache mod_rewrite to Nginx rewrite rules -
my site running on nginx , trying add software in sub-directory of site uses apache's mod_rewrite rules. e.g. www.mydomain.com/mysubfolder
here apache .htaccess
#options -indexes <ifmodule mod_rewrite.c> rewriteengine on rewritecond %{request_uri} ^/system.* rewriterule ^(.*)$ index.php?/$1 [l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^(.+)$ index.php?/$1 [l] </ifmodule> so far managed main page work when requesting login page, causing url redirect loop. e.g. www.mydomain.com/login this:
location /mysubfolder { if (!-e $request_filename) { rewrite ^(.*)$ /mysubfolder/index.php?q=$1 last; break; } } i have been reading , trying learn how convert apache nginx , used .htaccess nginx converter found @ http://winginx.com/htaccess tool doesn't seem recognize %{request_uri} ^/system.* part. upon research , study, came with:
location /mysubfolder { if ($request_uri ~ "^/(system.*)$") { rewrite ^/(.*)$ index.php?/$1 last; } if (!-e $request_filename) { rewrite ^(.+)$ /mysubfolder/index.php?q=$1 last; break; } } i complete noob @ , wondering if close accomplish conversion work. please help.
thank you.
was wondering if close accomplish conversion work
you've taken wrong approach use in nginx.
although kind of natural assume rewrite rules in apache mapped rewrite in nginx, aren't. instead mapped location rules.
your block mysubfolder should like:
location ^/mysubfolder { try_files /mysubfolder/index.php?$args =404; } you aren't rewriting - telling nginx requests start /mysubfolder should served files listed in try_files. btw have tell nginx pass query string through args doing.
you can append original url (i think) though may easier use $_server['request_uri'] inside script.
i believe rewrite rule have same start uri causing /mysubfolder keep matching.
in nginx rewriting used when want make external url paths served different internal urls, , rewrite rule not inside location block.
for example have file server, serves images , other files. have these rewrite rules in server block:
rewrite ^/image/(\d+)/(\w+)/(.+)\.([^\.]*)$ /proxy/proxyimage.php?typeid=$1&mode=$2&imagepath=$3.$4&resizeallowed=true&type=image last; rewrite ^/image/(\d+)/(.+)\.([^\.]*)$ /proxy/proxyimage.php?typeid=$1&imagepath=$2.$3&resizeallowed=true last; rewrite ^/file/(\d+)/(.+)\.([^\.]*)$ /proxy/proxyfile.php?typeid=$1&imagepath=$2.$3&resizeallowed=false last; to make external urls nice. served location block:
location ~* ^/proxy { try_files $uri =404; fastcgi_pass unix:/opt/local/var/run/php54/php-fpm-images.sock; include /documents/projects/intahwebz/intahwebz/conf/fastcgi.conf; } the location block doesn't need know url rewrites because done before location block encountered.
Comments
Post a Comment