TYPO free

home

fighting for TYPO free code

Switching the baseURL

27 Jun 2008

A couple of weeks ago I thought the price of the mobile pipes and tubes had come down far enough to give them a try. So I went over to the local pipes and tubes distributor and shackled myself to a year-long agreement with them. I was totally happy the first train trip home, doing a video chat with Ben. All seemed to work quite well, apart from the occasional connection drop (there's always one between Arnhem and Ede).

Now the mobile pipes and tubes version I got allows for 250MB of data a month. For me this is enough. I really don't want to overdose! I only occasionaly want to look stuff up when traveling to and from work. The provider tries to help you save money by pushing all the images through some kind of proxy that fscks up all the code and images I request.

All fine and dandy when you're just looking stuff up (although it does not look pretty), but when developing a site, it a nono. The HTML source is reduced to one loooooong line of HTML and a lot of javascript is added to replace all the calls to images. The TYPO3 backend breaks in some places because of all this compression and addition of script.

At the time I was experimenting with GIFBUILDER. So Backend issues aside, I was really pissed off at the mobile pipes and tubes provider for fscking up my code and images.

Lucky for me, I run some backends over https. I noticed that all traffic coming over https was left untouched. Of course! :-) What a find. All https traffic is encrypted between the sender and reciever, so those packets are not fscked up.

So I happily went on testing GIFBUILDER and all was well, or was it? Every time I clicked a link on a https loaded page of my site, I got redirected back to http. This is of course because of the baseURL setting in the HTML source. I found a solution to my problem using conditions.

  // Base URL
config.baseURL = typofree.org
[globalString = _SERVER|HTTPS=on]
config.baseURL = https://typofree.org/
[global]

That bit of TS nicely sets the baseURL according to the request protocoll. This kind of setup can of course also be used when developing a website. You know . . . the boring chores to do right before the site goes live, like adjusting all the email addresses and the baseURL.

[globalString = _SERVER|HTTP_HOST=www.somedomain.com]
config.baseURL = www.somedomain.com
[global]

[globalString = _SERVER|HTTP_HOST=somedomain.development.netcreators.com]
config.baseURL = somedomain.development.netcreators.com
[global]

Nice!

Read TSRef!

Note that for variables like HTT_HOST you can also use IENV/ENV. Check the phpinfo() in the install tool to see what is available exactly.

 [globalString = IENV:HTTP_HOST=www.somedomain.com]

And as an added bonus, I just thought of this (in TS constants):

[globalString = _SERVER|HTTP_HOST=www.somedomain.com]
formEmail = [email protected]
[global]

[globalString = _SERVER|HTTP_HOST=somedomain.development.netcreators.com]
formEmail = [email protected]
[global]

This way you don't have to remember switching email addresses right before you go live. Just set up these conditions in the constants section of the site and never think about them again. When you need to test a form, just pull up the site using the test domain (if that's still in place) and send the form just as the client would. This time however it will be sent to the testing address! :-)

Sebastian 30 Jun 2008, 08:32
Thats some real great stuff. I did already used conditionals on baseurl for https sometimes, but that was only with https_enforcer. Your way is very neat.

Thanks a lot.
Benni 1 Jul 2008, 10:25
Hey Michiel,

nice stuff, I do exactly the same for my installations :). I see we're on the same track here.
Check out this issue: https://bugs.typo3.org/view.php?id=7937
Commenting is closed for this item