Wordpress NGINX redirect everything to new domain EXCEPT -


i have unusual setup in have angularjs application running on http://example.com pulls data via wordpress api located @ http://api.example.com.

http://api.example.com needs have /wp-login, /wp-admin, /wp-content, , /wp-includes urls work if still regular wordpress site.

however other url's http://api.example.com/category/excategory or http://api.example.com/this-is-a-post-title need redirect 301 http://example.com domain.

example:

http://api.example.com/category/excategory 

redirects

http://example.com/category/excategory 

but

http://api.example.com/wp-admin (and after it) 

does not.

i've tried kinds of crazy things, location blocks seem either conflict, or weird url's go nowhere.

here's try failed:

location ~ /wp-(?:admin|login|includes|content) { index index.php; try_files $uri $uri/ /index.php?$args; }  location / {    return 301 $scheme//example.com$request_uri } 

put code in wp theme functions.php file. should redirect urls except 1 contain wp-admin:

 add_action('init','_redirect_api_url');   function _redirect_api_url(){     $redirect = true;     $pathnottoredirect = array('wp-admin','wp-content', 'wp-login','wp-includes');     $path = "http://example.com".$_server['request_uri'];     foreach($pathnottoredirect $val){         if(strpos($path, $val)){            $redirect = false;            break;           }     }     if($redirect == true) {        header("location: ".$path);      }  } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -