apache - (mod_rewrite) Redirect / cloack to subdirectory -
i'm trying redirect
to
with "/subdir" being cloaked user. @ least in url-bar.
what figured out based on rudimentary knowledge:
rewriteengine on rewriterule ^(/(.*))?$ http://www.domain.com/subdir/$1 [p,l]
it's working in terms of redirection, it's not cloacking. tips?
first, according official mod_rewrite documentation, if substituion part absolute url external redirect might happen (causing url change in user's browser; however, mod_rewrite should check if absolute url matches request , strip part out, i've checked version 2.2 , redirect happens).
so, 1 idea use relative url /subdir/$1
this looks good, not solve problem, because not work @ all.
instead, suggest always internally add subdir/
:
rewriterule ^subdir/.* - [pt] rewriterule (.*) /subdir/$1
a short explanation:
- the first slash
/
not included in pattern, resulting in pattern:http://www.domain.com/
-->''
http://www.domain.com/dir1/file1.html
-->dir1/file1.html
- to prevent adding
subdir/
repeatingly/recursively first rule passes through [pt] if it's yet modified - the second rule adds
subdir/
before entered
note 2 rules always add subdir/
in url internally (not visible user). if want add part requests root directory, need modify rules, of course - on might clarify use-case in question.
if plan use mod_rewrite more highly suggest reading mod_rewrite documentation apache server version (i guess 2.0 or 2.2 in case) , maybe blog articles (or other questions here @ so).
Comments
Post a Comment