How can I get both of these rules to work? RewriteRule ^example/? /new-example/ [R=302,L] RewriteRule ^example/new-stuff/? /new-example/new-stuff/ [R=302,L]
assuming "example" is the same in both rules, you can actually do that in one rule by capturing the optional subdirectory in the pattern and using the back reference in the target.
lucy24
2:27 am on Sep 14, 2012 (gmt 0)
... and as long as you're there, may as well allow for "index.html" -- or php or whatever it is you really use -- so you can redirect those in the same rule:
directory(/(index\.html)?)?$ {et cetera}
Otherwise some people will be redirected twice.
rwilson
2:28 am on Sep 14, 2012 (gmt 0)
Cool! "example" is the same, how would I go about doing that?
phranque
4:55 am on Sep 14, 2012 (gmt 0)
you can group something in your pattern by surrounding it with parentheses. when something is captured in a group it can be reused by referring back to it with a variable in the substitution.
Back-references are identifiers of the form $N (N=0..9), which will be replaced by the contents of the Nth group of the matched Pattern.: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule