Custom Virtual Host Syntax

edvanleeuwen

Verified User
Joined
Nov 18, 2013
Messages
155
I am trying to pass all requests from domain.com to https://www.domain.com, but not for alt.domain.com. I created alt.domain.com as a normal domain, not a subdomain.

I created a custom token to indicate what the base domain is:

Code:
DOMAIN_T=domain.com

In the custom virtual_host2.conf I put:
Code:
|?BASEDOMAIN="0"|
|*if DOMAIN=DOMAIN_T|
        |?BASEDOMAIN="1"|
|*endif|
|*if DOMAIN=DOMAIN_O|
        |?BASEDOMAIN="1"|
|*endif|
|*if BASEDOMAIN="1"|
        ServerName www.|DOMAIN|
        ServerAlias www.|DOMAIN| |DOMAIN| |SERVER_ALIASES|
        Redirect "/" "https://www.|DOMAIN|/"
|*else|
        ServerName |DOMAIN|
        ServerAlias |DOMAIN| |SERVER_ALIASES|
        Redirect "/" "https://|DOMAIN|/"
|*endif|

Although the BASEDOMAIN is set properly to "1" when the domain is the base domain, the virtual host config always shows the else part.

Does anyone see what I am missing?
 
Hello,

Is DOMAIN_T and DOMAIN_O are custom tokens here? IF so then you should use:

Code:
|?BASEDOMAIN="0"|
|*if DOMAIN=`DOMAIN_T`|
        |?BASEDOMAIN=1|
|*endif|
|*if DOMAIN=`DOMAIN_O`|
        |?BASEDOMAIN=1|
|*endif|
 
Thanks. You are right that the backquotes should be used.

However, I am still not able to get it working. I changed the script to this:

Code:
|?BASEDOMAIN="0"|
|*if DOMAIN=`DOMAIN_T`|
        |?BASEDOMAIN="1"|
|*endif|
|*if DOMAIN=`DOMAIN_O`|
        |?BASEDOMAIN="1"|
|*endif|

|*if BASEDOMAIN="1"|
        ServerName [url]www.|DOMAIN|[/url]
        ServerAlias [url]www.|DOMAIN|[/url] |DOMAIN| |SERVER_ALIASES| |BASEDOMAIN| |DOMAIN_T| 1
        Redirect "/" "https://www.|DOMAIN|/"
|*endif|

|*if BASEDOMAIN!="1"|
        ServerName |DOMAIN|
        ServerAlias |DOMAIN| |SERVER_ALIASES| |BASEDOMAIN| |DOMAIN_T| 0
        Redirect "/" "https://|DOMAIN|/"
|*endif|

It always returns the 0-part.
 
OK, try this syntax:


Code:
|*if DOMAIN="`DOMAIN_T`"|
        |?BASEDOMAIN=1|
|*endif|
|*if DOMAIN="`DOMAIN_O`"|
        |?BASEDOMAIN=1|
|*endif|


Note the double-quotes.
 
Thanks, tried it, didn't work.

I tried all combinations of ` and " even on both sides of the equation.
 
I have taken a different approach.

In virtual_host2.conf:

Code:
        ServerName |PREFIX_DOMAIN||DOMAIN|
        ServerAlias |PREFIX_DOMAIN||DOMAIN| |DOMAIN| |SERVER_ALIASES|
        Redirect "/" "https://|PREFIX_DOMAIN||DOMAIN|/"

In the first CUSTOM_HTTPD section of every domain

Code:
|?PREFIX_DOMAIN=www.|
or
Code:
|?PREFIX_DOMAIN=|

This works fine (and I think is even prettier and more maintainable)!
 
Back
Top