Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed redirection bug #63

Merged
merged 1 commit into from
Jan 26, 2014

Conversation

IJMacD
Copy link
Contributor

@IJMacD IJMacD commented Dec 26, 2013

In the case of MOD_REWRITE being used on an Apache server to forge the webtrees url,
webtrees would try to redirect to its source directory path and would not respect
the SERVER_URL site setting (causing an infinite redirect loop).

Further explanation:

Suppose the webtrees source is in a folder named /webtrees in the document root of the webserver but suppose you want the URL for your site to be something like http://example.com/familytree.

Previously webtrees would not handle this situation correctly and set the WT_SCRIPT_PATH constant based on its file path (/webtrees from $_SERVER['SCRIPT_NAME']). This constant however is used in URL generation e.g. LOGIN_URL. It should therefore be calculated from the incoming URL.

The result is all links generated which are based on WT_SCRIPT_PATH will take the user to a different URL root; moreover trying to set the SERVER_URL site setting in the database causes in infinite redirect loop since Apache tries to redirect to the favoured URL and webtrees sees it does not match the file directory and tries to redirect back.

This commit fixes the bug - if only for the Apache redirect case. I believe this is at least better than no fix at all.

In the case of MOD_REWRITE being used on an Apache server to forge the webtrees url,
webtrees would try to redirect to its source directory path and would not respect
the SERVER_URL site setting (causing an infinite redirect loop)
@fisharebest
Copy link
Owner

The ZF library has functions to extract the request URL from the server environment. Would it be better to use that?

Perhaps something along these lines...

$request = new Zend_Controller_Request_Http;
echo $request->getScheme() . '://' . $request->getHttpHost() . $request->getBaseUrl();

Does this code pick up your redirection OK?

@IJMacD
Copy link
Contributor Author

IJMacD commented Dec 31, 2013

Unfortunately, it doesn't. I've looked through all the Zend documentation about the Request classes. It seems that they aren't designed to catch this case. They use the same server variables as Webtrees currently uses.

The problem is that Zend applications are designed to have a single entry point index.php for example and you would have a rewrite rule such as (the recommended):

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php [NC,L]

This means unless the file actually exists (images, css etc.) route everything through the file index.php

Because Webtrees does not work this way and has multiple entry points e.g. index.php, login.php, individual.php the code from the Zend class can't correctly guess the base URL - it assumes you want /path/index.php instead of /path.

For reference here's the relevant part of my .htaccess file:

RewriteRule ^family$ /family/ [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^family/(.*)$ /webtrees/$1 [L]

@fisharebest
Copy link
Owner

The problem is that Zend applications are designed to have a single entry point

We know the current script name, so it is straightforward to strip that off. The Zend library Zend_Controller_Request_http::setRequestUri() appears to read the original request (whereas the WT code reads the actual file/script), so I was hoping that it would detect your request (family) rather than the actual path (webtrees).

FYI, the intention is to move to ZF2 and a single entry point (i.e. a front controller).

I don't have apache on my dev machine (I prefer nginx), so I'll need to set it up to investigate...

fisharebest added a commit that referenced this pull request Jan 26, 2014
@fisharebest fisharebest merged commit 73bfe2c into fisharebest:master Jan 26, 2014
@fisharebest
Copy link
Owner

Thanks!

@IJMacD IJMacD deleted the redirected_script_url branch January 27, 2014 03:48
@ghost ghost mentioned this pull request Aug 9, 2020
@webtrees-pesz webtrees-pesz mentioned this pull request Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants