-->

Typo3 : using typoscript to modify the base-url

2019-08-20 13:31发布

问题:

I am trying out TYPO3's introduction package. For that I am using Xampp on my computer.

I have installed it in a subdirectory, but since it uses "real-url", I need to modify the generated links, so that instead of http://localhost/about-typo3/ I get http://localhost/subfolder/about-typo3/

I believe it must be done via "typo-script", and from what I have read on the Internet, this line should do the job :

config.baseURL = http://localhost/subfolder/

But I don't know where I should put it. I have tried different locations, but with no apparent effect.

So what I would like to know is : am I on the good path for what I need to do, and if yes, what should I try now ?

回答1:

This is a bug in the 4.6 Introduction Package. 4.7 will ship with a correct version, so you might just want to go ahead and try the Introduction Package from 4.7RC2 (Preview Releases).

For now, just choose Template in the module menu on the left. Then use the dropdown to select Constant Editor. Now choose the page HOME in the pagetree on the middle. Now use the second dropdown to select CONFIG. There modify the topmost setting Absolute URI prefix. Input your full domain without the last slash (/). That means copy your current URL from the browser and strip /typo3/backend.php. Now save with the little save icon in the top toolbar. This will also invalidate all caches for you (because you changed the topmost template). No need to install extra extensions or to do this manually.

Alternative you can fix the actual bug. Go to template module and select the folder TypoScript Templates / page_configuration. Now select Info/Modify instead of Constant Editor and directly above the table page.config. The click the pencil left of Setup. Find the line absRefPrefix = {$config.absRefPrefix}/. This should be around line 62 (4.7RC2). Remove the last slash (/) from that line and save. Because you are not on the topmost template, you need to clear the cache. On the topright of your screen, you can find the yellow flash icon. Click it and select Clear all caches (red flash). Now go to you website again.

A general note about (config.)baseURL. This is more a hack, because it just tells the browser to behave as if the website would be at another place. The correct way is to create correct links in first place. You should use (config.)absRefPrefix instead. To make this work in auto mode, it must be completely empty (config.absRefPrefix =). Do not use baseURL any more. The next Introduction Package will not have this setting.

Yet another note: If you use the config.absRefPrefix, you have to include the last slash (/). The only reason why you do not have to do so above (in the constants), is because it is hardcoded in the template and thus also preventing the automatic detection to work.



回答2:

If you are using different hosts, you can use typoscript conditions in your root template:

# Default:
config.baseURL = http://www.example.com/

[globalString = ENV:HTTP_HOST=sub1.example.com]
config.baseURL = http://sub1.example.com/
[global]

[globalString = ENV:HTTP_HOST=sub2.example.com]
config.baseURL = http://sub2.example.com/
[global]


回答3:

if you are using introduction package. there is Constant for set the base url

Go to 'Template' and 'Constant Editor.. you can find 'Domain name for Base URL [config.domain]' .. for setting base url

also you can put the config.baseURL = http://localhost/subfolder/ on 'Info Modify' Setup field

hope will help you .. sorry for my bad english