mod rewrite - mod_rewrite aliasing a subdirectory -
i'm struggling mod_rewrite always. have number of client portals running through wordpress multisite, accessed through subdirectory: portal
.
so example: http://www.mydomain.com/portal/clienta/
i'd able there typing http://www.mydomain.com/clienta/
, redirect me http://www.mydomain.com/portal/clienta/
here's have far, , it's not producing rewrite can tell:
rewritecond %{request_uri} /portal/ rewritecond %{request_filename} -f rewritecond %{request_filename} -d rewriterule . - [s=1] rewriterule /clienta(/?) /portal/clienta/ # begin wordpress <ifmodule mod_rewrite.c> rewriteengine on rewritebase / rewriterule ^index\.php$ - [l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule . /index.php [l] </ifmodule> # end wordpress
the second part can't touch because wordpress needs it. pattern trying anticipate not putting in trailing slash, hence (/?)
edit: should note don't want create more general rule - i'm comfortable having add rewrite rule each new client , increasing s=x
number each time.
edit (aug 11), after little more puttering .htaccess at:
rewriteengine on rewriterule ^clienta(/?) /portal/clienta/ [r] # begin wordpress <ifmodule mod_rewrite.c> rewriteengine on rewritebase / rewriterule ^index\.php$ - [l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule . /index.php [l] </ifmodule> # end wordpress
needless doesn't work. however, first part works if delete entire wordpress section. need them both work simultaneously. wordpress piece causing failure of first section? suppose it's combination of rewritebase , last rule aliases else /index.php, frankly bit of bummer. in fact don't understand how rule work in multisite context, , yet seems to.
final solution lazyone correct answer! others' reference, final solution used was:
rewriteengine on rewriterule ^clienta(/.+)? /portal/clienta$1 [r,l] rewriterule ^clientb(/.+)? /portal/clientb$1 [r,l] # begin wordpress <ifmodule mod_rewrite.c> rewriteengine on rewritebase / rewriterule ^index\.php$ - [l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule . /index.php [l] </ifmodule> # end wordpress
as simple this:
rewritecond %{request_uri} !^/portal/ rewriterule (.*) /portal/$1 [l]
it rewrite (internal redirect) requests /portal/
folder (e.g. /clienta/something
=> /portal/clienta/something
).
if need clients (or, better say, specific folders clients while still having general/common folders is), can use rule each client:
rewriterule ^clienta(.*) /portal/clienta$1 [l]
so .htaccess this:
rewriterule ^clienta(.*) /portal/clienta$1 [l] rewriterule ^clientb(.*) /portal/clientb$1 [l] # begin wordpress <ifmodule mod_rewrite.c> rewriteengine on rewritebase / rewriterule ^index\.php$ - [l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule . /index.php [l] </ifmodule> # end wordpress
Comments
Post a Comment