0

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?

Aminah Nuraini
  • 18,120
  • 8
  • 90
  • 108

1 Answers1

0

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

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • How are you testing it? Can you show full code in your question? – anubhava Dec 11 '18 at 06:47
  • Hmmmm, I get this error `[Tue Dec 11 16:09:05.587936 2018] [core:alert] [pid 19988:tid 1984] [client ::1:55876] D:/htdocs/myproject/.htaccess: RewriteBase: argument is not a valid URL`. Does that help? – Aminah Nuraini Dec 11 '18 at 09:10
  • I have provided full code that is working fine on my local Apache – anubhava Dec 11 '18 at 10:50