You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*`rules` {Array} The set of rewriting rules to apply to each request
567
+
*`operation` {String} Operation type (`and` or `or`) **Default:**`and`
568
+
*`conditions` {Array} Conditions to match against the request
569
+
*`type` {String} Condition type
570
+
*`args` {String} Arguments to pass to condition constructor
571
+
*`rewriters` {Array} Rewrites to apply if the conditions match
572
+
*`type` {String} Rewriter type
573
+
*`args` {String} Arguments to pass to rewriter constructor
574
+
* Returns: {Rewriter}
575
+
576
+
Construct a Rewriter to rewrite requests before they are dispatched to PHP.
577
+
578
+
```js
579
+
import { Rewriter } from'@platformatic/php-node'
580
+
581
+
constrewriter=newRewriter([{
582
+
conditions: [{
583
+
type:'header',
584
+
args: ['User-Agent', '^(Mozilla|Chrome)']
585
+
}],
586
+
rewriters: [{
587
+
type:'path',
588
+
args: ['^/old-path/(.*)$', '/new-path/$1']
589
+
}]
590
+
}])
591
+
```
592
+
593
+
#### Conditions
594
+
595
+
There are several types of conditions which may be used to match against the
596
+
request. Each condition type has a set of arguments which are passed to the
597
+
constructor of the condition. The condition will be evaluated against the
598
+
request and if it matches, the rewriters will be applied.
599
+
600
+
The available condition types are:
601
+
602
+
-`exists` Matches if request path exists in docroot.
603
+
-`not_exists` Matches if request path does not exist in docroot.
604
+
-`header(name, pattern)` Matches named header against a pattern.
605
+
-`name` {String} The name of the header to match.
606
+
-`pattern` {String} The regex pattern to match against the header value.
607
+
-`method(pattern)` Matches request method against a pattern.
608
+
-`pattern` {String} The regex pattern to match against the HTTP method.
609
+
-`path(pattern)`: Matches request path against a pattern.
610
+
-`pattern` {String} The regex pattern to match against the request path.
611
+
612
+
#### Rewriters
613
+
614
+
There are several types of rewriters which may be used to rewrite the request
615
+
before it is dispatched to PHP. Each rewriter type has a set of arguments which
616
+
are passed to the constructor of the rewriter. The rewriter will be applied to
617
+
the request if the conditions match.
618
+
619
+
The available rewriter types are:
620
+
621
+
-`header(name, replacement)` Sets a named header to a given replacement.
622
+
-`name` {String} The name of the header to set.
623
+
-`replacement` {String} The replacement string to use for named header.
624
+
-`href(pattern, replacement)` Rewrites request path, query, and fragment to
625
+
given replacement.
626
+
-`pattern` {String} The regex pattern to match against the request path.
627
+
-`replacement` {String} The replacement string to use for request path.
628
+
-`method(replacement)` Sets the request method to a given replacement.
629
+
-`replacement` {String} The replacement string to use for request method.
630
+
-`path(pattern, replacement)` Rewrites request path to given replacement.
631
+
-`pattern` {String} The regex pattern to match against the request path.
632
+
-`replacement` {String} The replacement string to use for request path.
633
+
563
634
## Contributing
564
635
565
-
This project is part of the [Platformatic](https://github.com/platformatic) ecosystem. Please refer to the main repository for contribution guidelines.
636
+
This project is part of the [Platformatic](https://github.com/platformatic)
637
+
ecosystem. Please refer to the main repository for contribution guidelines.
0 commit comments