Convert Rewrite Rule Prefix Matching from Apache to Nginx -


how convert apache's prefix matching nginx?

rewritecond %{request_uri} ^/test1 rewriterule ^(.*)$ http://newsite/$1 [r=301,l]  rewritecond %{request_uri} ^/foo rewriterule ^(.*)$ http://newsite/$1 [r=301,l]  rewritecond %{request_uri} ^/bar rewriterule ^(.*)$ http://newsite/$1 [r=301,l] 

or

rewriterule ^/test1/(.*)$ http://newsite/test1/$1 [r=301,l] rewriterule ^/foo/(.*)$ http://newsite/foo/$1 [r=301,l] rewriterule ^/bar/(.*)$ http://newsite/bar/$1 [r=301,l] 

is this?

location / {    rewrite ^/(test1|foo|bar)/(.*)$   http://newsite/$1/$2 permanent;    ... } 

your rewrite not bad. work. thing people prefer return directive in nginx because little faster (nginx needs less processing).


i'm not familiar apache rewrites might wrong in interpretation of them believe want rewrite urls under /test1, /foo , /bar. purpose not need rewrite directive, can make simple return in nginx

location /test1 {     return 301 http://newsite$request_uri; } location /foo {     return 301 http://newsite$request_uri; } location /bar {     return 301 http://newsite$request_uri; } location / {     ...  # pages on domain } 

using regex little slower:

location ~ /(test1|foo|bar) {     return 301 http://newsite$request_uri; } 

and can use rewrite directive too, if want:

location ~ /(test1|foo|bar) {     rewrite ^ http://newsite$request_uri permanent; } 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -