Recipe 5.11 Replacing Text in Requested URLs


You want to change all occurrences of string1 to string2 in a request's URI.


RewriteCond %{REQUEST_URI} "string1" RewriteRule "(.*)string1(.*)" "$1string2$2" [N,PT]


The [N] flag tells Apache to rerun the rewrite rule. This rule will get run repeatedly until the RewriteCond fails. Thus, it will get rerun as long as the URL contains the string that you want to replace. As soon as all occurrences of this string have been replaced, the RewriteCond will fail, and the rule will stop. The [PT] tells mod_rewrite to pass the rewritten URL on to the rest of Apache for any additional processing once the rewriting is done.

See Also

  • Appendix A

Apache Cookbook
Apache Cookbook: Solutions and Examples for Apache Administrators
ISBN: 0596529945
EAN: 2147483647
Year: 2006
Pages: 215

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: