Project

General

Profile

Actions

Bug #14856

closed

TYPO3_SITE_URL is not set correct

Added by old_babel over 19 years ago. Updated over 11 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Backend API
Target version:
-
Start date:
2005-07-11
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
3.8
PHP Version:
Tags:
Complexity:
hard
Is Regression:
Sprint Focus:

Description

In file t3lib/class.t3lib_div.php the computation of TYPO3_SITE_URL seems to be wrong in my case. Look at the code. In my test case

PATH_thisScript = /pub/www/linum/vhost/index.php
PATH_site = /pub/www/linum/vhost/

have these values. If lPath is computed the dirname(PATH_thisScript) resolved to /pub/www/linum/vhost. So the substr command is called like

$lPath = substr("/pub/www/linum/vhost",strlen("/pub/www/linum/vhost")).'/';

which computes to a "/" string. I think lPath should contain index.php (in my case). Now the remaining part of the calculation leads to wrong result. Reading the typo3 documentation I understand that TYPO3_SITE_URL should always point to the real typo3 Site URL. This is really difficult if the typo3 site URL is somewhere else than / of the site. A broken TYPO3_SITE_URL causes TYPO3_SITE_SCRIPT to be broken too.

SERVER: SERVER_SOFTW: Apache/1.3.26 (Unix) Debian GNU/Linux mod_gzip/1.3.19.1a mod_ssl/2.8.9 OpenSSL/0.9.6c PHP/4.3.11-0.dotdeb.0
SERVER: GATEWAY_INTE: CGI/1.1
OTHER: TYPO3_VERSION: 3.8.0
OTHER: PHP_VERSION : 4.3.11-0.dotdeb.0

(issue imported from #M1274)


Related issues 4 (0 open4 closed)

Related to TYPO3 Core - Bug #14410: RealURL does not work, because TYPO3_SITE_URL value is wrongClosed2004-11-24

Actions
Related to TYPO3 Core - Bug #17878: mod_rewrite redirect to subdirectory + realurl = page not foundClosed2007-12-03

Actions
Related to TYPO3 Core - Bug #21791: Output of t3lib_div::getIndpEnv for TYPO3_SITE_SCRIPT for Rewritten URLsClosed2009-12-03

Actions
Related to TYPO3 Core - Bug #18816: TYPO3_SITE_URL in t3lib_div::locationHeaderUrl to support TYPO3 installed in subfoldersClosedPeter Niederlag2008-05-19

Actions
Actions #1

Updated by old_babel over 19 years ago

I've just create a a test web on a pure debian sarge system. And the problem is still there. To reproduce the problem simply install Debian Sarge with these packages:

funfix:/pub/dummy/typo3conf# COLUMNS=150 dpkg -l | grep apa
ii apache2-common 2.0.54-4 next generation, scalable, extendable web server
ii apache2-mpm-prefork 2.0.54-4 traditional model for Apache2
ii apache2-utils 2.0.54-4 utility programs for webservers
ii libapache2-mod-chroot 0.4-2 run Apache in a secure chroot environment
ii libapache2-mod-php4 4.3.10-15 server-side, HTML-embedded scripting language (apache 2.0 module)
ii libapache2-mod-python2.3 3.1.3-3 An Apache 2 module that embeds Python 2.3 within the server

I've installed a fresh copy of typo3 3.8.0 with the dummy package. I've choosen template "GLUECK" as a sample.

This is in my localconf.php:

$TYPO3_CONF_VARS['EXTCONF']['realurl'] = array(
'_DEFAULT' => array(
'fileName' => array (
'defaultToHTMLsuffixOnPrev' => true,
),
'pagePath' => array(
'type' => 'user',
'userFunc' => 'EXT:realurl/class.tx_realurl_advanced.php:&tx_realurl_advanced->main',
'spaceCharacter' => '-',
'languageGetVar' => 'L',
'expireDays' => 3,
'disablePathCache' => true,
),
),
);

This is in my template record setup:
config.simulateStaticDocuments = 0
config.baseURL = 1
config.tx_realurl_enable = 1

My /etc/apache2/sites-available/dummy file looks like:

<VirtualHost 192.168.193.251:80>
ServerName dummy.dmz.linum.com
ServerAdmin

DocumentRoot          /pub/dummy
TransferLog           /var/log/apache2/dummy-transfer
ErrorLog /var/log/apache2/dummy-error

RewriteEngine On
RewriteRule ^/(typo3temp|typo3|typo3conf|t3lib|tslib|fileadmin)/ - [L]
RewriteRule ^/typo3$ /typo3/ [L]
RewriteCond {DOCUMENT_ROOT}{REQUEST_FILENAME} !-f
RewriteCond {DOCUMENT_ROOT}{REQUEST_FILENAME} !-d
RewriteCond {DOCUMENT_ROOT}{REQUEST_FILENAME} !-l
RewriteRule .* /index.php

php_flag allow_call_time_pass_reference off
php_flag register_globals off
php_flag register_argc_argv off
php_flag magic_quotes_gpc off
php_value upload_max_filesize 10M
php_value memory_limit 32M
</VirtualHost>

Now create a directory structure with three level. Ebene1, Eben2 and Ebene3. Now browse Ebene1 and Ebene2. These will work. Now try to enter Ebene3. This show the broken base href that is caused by a broken TYPO3_SITE_URL. I hope this helps.

Actions #2

Updated by Stefan B¼hler over 19 years ago

.htaccess:
---------
[...]
  1. If you use the RealUrl extension, then you'll have to enable the next line.
  2. You will have to change this path if your TYPO3 installation is located
  3. in a subdirectory of the website root. #
  4. If you place this in httpd.conf, you cannot use this directive in any case!
    RewriteBase /
    [...]
    --------------
    => If you want to use RealUrl (or similar redirects), you have to use .htaccess

The computation of $lPath is correct, only the length of this string is really required.

[quote]
Reading the typo3 documentation I understand that TYPO3_SITE_URL should always point to the real typo3 Site URL. This is really difficult if the typo3 site URL is somewhere else than / of the site.
[/quote]
You are right - with a httpd.conf this is really difficult. And it is impossible to detect automatically (without configuration), where your site is. (You could write code which guess this; but this wouldn't be reliable).

Actions #3

Updated by old_babel over 19 years ago

Hmm, so you suggest that I try to use a dot-htaccess file instead of writing the Rewrite stuff directly to the http.conf file? After reading the quoting comments again I think I should read this stuff more carefully.

Thanks for the hint.

Actions #4

Updated by Stefan B¼hler over 19 years ago

I now have a solution for htttpd.conf:
--------------
RewriteRule ^/(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)(/.*)?$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^/(.*)$ /index.php [L,E=ORIG_SCRIPT_NAME:/index.php]
---------------
This sets the environment variable "ORIG_SCRIPT_NAME" to "/index.php" which Typo3 uses (if present) instead of "SCRIPT_NAME".
"SCRIPT_NAME" is only changed to this if you use .htaccess with RewriteBase, and it is not possible (as far as i know and tried) to change this from httpd.conf.
If your Typo3 is reachable e.g. at http://host/path-to-typo3/, you would change the RewriteRule to:
RewriteRule ^/(.*)$ /index.php [L,E=ORIG_SCRIPT_NAME:/path-to-typo3/index.php]

Actions #5

Updated by Karsten Dambekalns about 19 years ago

Stefan, your solution with setting the ORIG_SCRIPT_NAME works for me, too! Thanks a lot.

Now it remains a mistery why it works for some, and not for others, in other setups.

Actions #6

Updated by Ulrich Fischer over 17 years ago

I have problems with TYPO3_SITE_URL as well in TYPO3 Ver. 4.1.2.
The problems appeared with realURL, but i think it is general problem
an I suggest it is an old bug.

This is the way in t3lib/class.t3lib_div.php

1: case 'TYPO3_SITE_URL':
2: if (defined('PATH_thisScript') && defined('PATH_site')) {
3: $lPath = substr(dirname(PATH_thisScript),strlen(PATH_site)).'/';
4: $url = t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR');
5: $siteUrl = substr($url,0,-strlen($lPath));
6: if (substr($siteUrl,-1)!='/') $siteUrl.='/';
7: $retVal = $siteUrl;
8: }
9: break;

My Variables:
PATH_thisScript = /import/www/vhosts/my-domain/index.php
PATH_site = /import/www/vhosts/my-domain/
dirname(PATH_thisScript) = /import/www/vhosts/my-domain

3: $lPath = '/' [<-correct]
I think it is correct, because typo3 is in the root located.

Now the bug appears. TYPO3_REQUEST_DIR gives an "url" ? with a follwing directory

4: $url http://www.my-domain.my-server.com/my-subdirectory/

So let us have a look to ---------------------------------------------------------------------
11: case 'TYPO3_REQUEST_DIR':
12: $retVal = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST').t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')).'/';
13: break;

My Variables:
TYPO3_REQUEST_HOST = http://www.my-domain.my-server.com [<- correct]
SCRIPT_NAME = /my-subdirectory/test-page.html
SCRIPT_NAME in this case is the "real" name.
In most cases SCRIPT_NAME = 'index.php'
So in this case there is t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')) = /my-subdirectory
which is, i think, C O R R E C T for TYPO3_REQUEST_DIR.
----------------------------------------------------------------------------------------------

My suggestion is, to fetch TYPO3_REQUEST_HOST for the host
and then append "lPath", which has identified the subdirectory of typo3 installation.
Or did I think wrong? Can there be a difference between physical and virtuell subdirectory?

4: $host = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST');
5: $siteUrl = $host.$lPath;

and the whole part

1: case 'TYPO3_SITE_URL':
2: if (defined('PATH_thisScript') && defined('PATH_site')) {
  1. 3: $lPath = substr(dirname(PATH_thisScript),strlen(PATH_site)).'/';
  2. 4: $url = t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR');
    4: $host = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST');
    5: $siteUrl = $host.$lPath;
    5: $siteUrl = substr($url,0,-strlen($lPath));
    6: if (substr($siteUrl,-1)!='/') $siteUrl.='/';
    7: $retVal = $siteUrl;
    8: }
    9: break;
Actions #7

Updated by Ulrich Fischer over 17 years ago

After testing I see it is a bit more complecated, thanI thought.
There are 2 different files, which define PATH_thisScript!

1. index.php (frontend)
define('PATH_site', dirname(PATH_thisScript).'/');

2. typo3/init.php
define('PATH_site', substr(PATH_typo3,0,-strlen(TYPO3_mainDir))); // Abs. path to directory with the frontend (one above the admin-dir)

The second definition makes more sense to find TYPO3_SITE_URL, but class.t3lib_div.php does not know about this difference.

My suggested "patch":
case 'TYPO3_SITE_URL':
if (defined('PATH_thisScript') && defined('PATH_site')) {
#org $lPath = substr(dirname(PATH_thisScript),strlen(PATH_site)).'/';
#org $url = t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR');
#org $siteUrl = substr($url,0,-strlen($lPath));

  1. Inserted by sunfish
    $path_frontend_dir = substr(PATH_typo3,0,-strlen(TYPO3_mainDir)); // Abs. path to directory with the frontend (one above the admin-dir) <== PATH_site in init.php
    $lPath = substr(dirname(PATH_thisScript),strlen($path_frontend_dir)).'/';
if(TYPO3_MODE == 'FE') {
$host = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST');
$siteUrl = $host.$lPath;
}
else
// (TYPO3_MODE == 'BE') { # same as before
$url = t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR');
$siteUrl = substr($url,0,-strlen($lPath));
}
  1. end of insert
    if (substr($siteUrl,-1)!='/') $siteUrl.='/';
    $retVal = $siteUrl;
    }
    break;
Actions #8

Updated by Andreas Wolf about 13 years ago

  • Category set to Backend API
  • Target version deleted (0)
  • TYPO3 Version changed from 3.8.0 to 3.8
  • PHP Version deleted (4)
  • Complexity set to hard
Actions #9

Updated by Alexander Opitz over 11 years ago

  • Status changed from New to Needs Feedback

As TYPO3 3.8 is very old and not supported any more, does this problem happen with newer TYPO3 CMS Versions like 4.5 or 6.0?

Actions #10

Updated by Ulrich Fischer over 11 years ago

With newer versions of typo3 e.g. greater than 4.5.0 I was not faced with this problem.

Actions #11

Updated by Alexander Opitz over 11 years ago

  • Status changed from Needs Feedback to Closed

Closed as of user comment.

Actions

Also available in: Atom PDF