My login redirect is being built with an absolute url but I need to use a relative url because my cakephp application is being served up through a proxy server.
The Router class has properties that effect the behavior of the url method (documentation link: http://api.cakephp.org/class/router#method-Routerurl )
I think what I want to do is set the 'base' property to false, but I'm not exactly sure how to do this. Do I just specify
$this->base = false;
somewhere? (I tried doing this in the beforeFilter in the controller but it had no effect).
Update: Well, it's not the ideal solution but I can get the links to work through the proxy server by adding this line to paths.php: define('FULL_BASE_URL','http://www.myexternaldomain.com');
and then I also had to set the security level to low in core.php.
But then this means that went I access the cake pages locally with http://localhostname/cake/users
I'll get redirected to the external url which is not what I would prefer.
Update:
Here is the output of a print_r($_SERVER) from my dev server:
Array ( [REDIRECT_REDIRECT_STATUS] => 200 [REDIRECT_STATUS] => 200 [HTTP_HOST] => devdataload [HTTP_USER_AGENT] => Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.11) Gecko/20101028 CentOS/3.6-2.el5.centos Firefox/3.6.11 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 [HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5 [HTTP_ACCEPT_ENCODING] => gzip,deflate [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7 [HTTP_KEEP_ALIVE] => 115 [HTTP_CONNECTION] => keep-alive [HTTP_REFERER] => http://devdataload/cakepf/users/login [HTTP_COOKIE] => CAKEPHP=ndhjfch0c1oq285ks4d2dfib90; ZDEDebuggerPresent=php,phtml,php3 [PATH] => /usr/bin:/bin [SERVER_SIGNATURE] => Apache/2.2.8 (CentOS) Server at devdataload Port 80 [SERVER_SOFTWARE] => Apache/2.2.8 (CentOS) [SERVER_NAME] => devdataload [SERVER_ADDR] => 5.213.249.197 [SERVER_PORT] => 80 [REMOTE_ADDR] => 5.213.249.197 [DOCUMENT_ROOT] => /var/www/html [SERV开发者_StackOverflowER_ADMIN] => root@localhost [SCRIPT_FILENAME] => /var/www/html/cakepf/app/webroot/index.php [REMOTE_PORT] => 39979 [REDIRECT_QUERY_STRING] => url=alerts [REDIRECT_URL] => /cakepf/app/webroot/alerts [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => url=alerts [REQUEST_URI] => /cakepf/alerts [SCRIPT_NAME] => /cakepf/app/webroot/index.php [PHP_SELF] => /cakepf/app/webroot/index.php [REQUEST_TIME] => 1299347553
Cake handles relative and absolute URLs just fine, as long as you don't hardcode them.
When specifying URLs you should always do so in terms of the targeted controller and action and let Cake figure out the actual URL.
An array('controller' => 'foos', 'action' => 'bar')
will be translated dynamically to /foo/bar
, /project/cake/foo/bar
or whatever else is appropriate. If you need an absolute URL, set the appropriate parameter to true
:
Router::url(array('controller' => 'foos', 'action' => 'bar'), true)
→ http://example.com/foos/bar
This solution isn't ideal but at least it's functional. In my production system I add this line into paths.php
:
define('FULL_BASE_URL','http://<proxy server name>');
This ensures that all urls go through the proxy server.
In dev/test
where I am only working locally, I comment that line out.
精彩评论