This will be a parse order issue, your if statement is an Advanced Conditional (Step 7 in Low's EE parse order) whereas member_id is a User Defined Global Variable (Step 9 in Low's EE parse order) so is parsed later. You'll notice the redirect works because it is on Step 8 (in Low's EE parse order) so the ordrr your template is parsed is as so :
- Advanced Conditional
- Redirect
- User Defined Global Variable
You see, when the redirect happens (and it happens straight away on the tag) it's too early for the member_id
.
You can use a little PHP snippet or pop a script based redirect in there, js won't be executed until it gets to the browser but relies on JS. The PHP solution will work with either PHp on Input or Output.
{if logged_in AND (segment_3 ~ "/[^\d+]/" OR segment_3 == "")}
{!-- Redirect to own profile if logged in--}
{redirect="account/profile/<?php echo ee()->session->userdata('member_id'); ?>"}
{/if}
That should get you cookin, interestingly you can do the entire logged in check with PHP if you desire, if used with PHP on Early parsing you can acheive some efficiency as the redirect will occur before the tags are all parsed on the template...
summin like (untested)...
<?php
if (
ee()->session->userdata('group_id') != 0 &&
preg_match( '/[^\d+]/', ee()->uri->segment(3,"X") )
) {
ee()->functions->redirect('account/profile/'.ee()->session->userdata('member_id'));
}
?>
Check out the EE User Data in the Session Class, Segements in the URI class and Redirect in Functions Class documentation.