pub struct Engine { /* private fields */ }Expand description
Expression Engine for Proccessing Rewrite Rules
Supports a subset of official
mod_rewrite expressions.
§Example
use mod_rewrite::Engine;
let mut engine = Engine::default();
engine.add_rules(r#"
RewriteRule /file/(.*) /tmp/$1 [L]
RewriteRule /redirect/(.*) /location/$1 [R=302]
RewriteRule /blocked/(.*) - [F]
"#).expect("failed to process rules");
let uri = "http://localhost/file/my/document.txt";
let result = engine.rewrite(uri).unwrap();
println!("{result:?}");Implementations§
Source§impl Engine
impl Engine
Sourcepub fn max_iterations(self, iterations: usize) -> Self
pub fn max_iterations(self, iterations: usize) -> Self
Configure max number of loops over entire ruleset during rewrite before error
Default is 10
Sourcepub fn add_rules(&mut self, rules: &str) -> Result<&mut Self, ExpressionError>
pub fn add_rules(&mut self, rules: &str) -> Result<&mut Self, ExpressionError>
Parse additonal Expressions to append as ExprGroups to the
existing engine.
Sourcepub fn rewrite(&self, uri: &str) -> Result<Rewrite, EngineError>
pub fn rewrite(&self, uri: &str) -> Result<Rewrite, EngineError>
Evaluate the given URI against the configured ExprGroup instances
defined and generate a Rewrite response.
This method skips using EngineCtx which is used to suppliment
Condition expressions. If you are NOT making use of RewriteCond
rules, this method may be simpler to use.
See Engine::rewrite_ctx for more details.
Sourcepub fn rewrite_ctx(
&self,
uri: &str,
ctx: &mut EngineCtx<'_>,
) -> Result<Rewrite, EngineError>
pub fn rewrite_ctx( &self, uri: &str, ctx: &mut EngineCtx<'_>, ) -> Result<Rewrite, EngineError>
Evaluate the given URI against the configured ExprGroup instances
defined and generate a Rewrite response.
This method uses an additional EngineCtx which is used to suppliment
variables expanded in Condition expressions.
If your engine is using RewriteCond rules, you will want to use this
method with a complete EngineCtx. See Engine::rewrite for a simpler
alternative.