jump to navigation

Problems under IIS February 11, 2006

Posted by rossoft in CakePHP.
trackback

I have IIS in my webhost provider… that sucks but that webhosting is cheap.
The IIS doesn’t have mod_rewrite, and I don’t have any configuration control.
Also, an url like this fails:
http://www.xxx.com/index.php/controller/action , so I have to hack the files a little to change the url to /index.php?url=/controller/action

This is a dirty copy-paste from the trac of cakephp

OK My modifications: This is for IIS without mod rewrite, and document root set to the root of the cake installation. In the wiki there is a tutorial for making it work installing a mod rewrite (My web provider doesn't permit installing mod's)

At the beginning of core.php, add the line:

define('SERVER_APACHE',false);

then replace the line define('BASE_URL',xxx) by:

if (SERVER_APACHE) {

                define ('BASE_URL', env('SCRIPT_NAME') ); }

else {

                define ('BASE_URL', env('SCRIPT_NAME') . '?url='); }

The file index.php of the root folder of the installation:

define ('APP_DIR', 'app'); define ('DS', DIRECTORY_SEPARATOR); define ('ROOT', dirname(FILE).DS);

require_once ROOT.'cake'.DS.'basics.php'; require_once ROOT.APP_DIR.DS.'config'.DS.'core.php'; require_once ROOT.'cake'.DS.'config'.DS.'paths.php';

$uri = setUri();

/**

    * As mod_rewrite (or .htaccess files) is not working, we need to take 

care

    * of what would normally be rewritten, i.e. the static files in 

/public

    */

if ($uri === '/' $uri === '/index.php') {

        $_GET['url'] = '/'; require_once ROOT.APP_DIR.DS.WEBROOT_DIR.DS.'index.php'; }

else {

        $elements = explode('/index.php', $uri); if(!empty($elements[1])) {

                $path = $elements[1]; if (! SERVER_APACHE) {

                        $path=substr($path,5);

                                $path=split('&',$path); $path=$path[0];

                }

        } else {

                $path = '/';

        }

        $_GET['url'] = $path;

        require_once ROOT.APP_DIR.DS.WEBROOT_DIR.DS.'index.php'; }

Finally, in AppController?.php , add the functions:

                                function referer() {

                                                if (env('HTTP_REFERER') && FULL_BASE_URL ) {

                                                                $base = FULL_BASE_URL . $this->webroot; if (strpos(env('HTTP_REFERER'), $base) == 0) {

                                                                                $referer=substr(env('HTTP_REFERER'), strlen($base)-3); if (! SERVER_APACHE) {

                                                                                                if (strpos($referer,"?url=")===0) {

                                                                                                                $referer=substr($referer,5);

                                                                                                } if (strpos($referer,"&")) {

                                                                                                                $referer=explode("&",$referer); $referer=$referer[0];

                                                                                                }

                                                                                } return $referer;

                                                                } else return '/';

                                                } else return '/';

                                }

                function redirect ($url) {

                                $this->autoRender = false; if(strpos($url, '/') !== 0) {

                                                $url = '/'.$url;

                                } if (function_exists('session_write_close')) {

                                        session_write_close();

                                } if (SERVER_APACHE) {

                                                header ('Location: '.$this->base.$url);

                                } else {

                                                header('Location: http://' . $_SERVER['HTTP_HOST'] . $this->base . $url);

                                }

                        }
Advertisements

Comments»

1. Celinda - June 11, 2014

Hi there, everything is going fine here and ofcourse every one is sharing information, that’s
in fact good, keep up writing.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: