IfDefine and RewriteBase doesn't work well tog

2019-03-06 14:21发布

When I use this code, it works just okay:

<IfDefine ${ServerBase}>
    RewriteBase ${ServerBase}
</IfDefine>

But when I add this, it always uses RewriteBase \ which was not what I want.

<IfDefine !${ServerBase}>
    RewriteBase /
</IfDefine>

The condition was already different. One of them when ServerBase is defined and one of them is when ServerBase is NOT defined. How can I use IfDefine else pattern with RewriteBase?

1条回答
你好瞎i
2楼-- · 2019-03-06 15:10

IfDefine checks whether a parameter is defined or not. It doesn't check it's value.

You need to use it as:

<IfDefine ServerBase>
    RewriteBase ${ServerBase}
</IfDefine>

<IfDefine !ServerBase>
    RewriteBase /
</IfDefine>

Note use of ServerBase instead of ${ServerBase}.

Check official Apache doc of IfDefine

查看更多
登录 后发表回答