Hide index.php and backend.php from an webapplication with front and back office

Hi !

That is my first post and day with Yii so please be tolerant…

I like beautifull url (and oher useless stuff: L for love :P) so let see a little tips to have a nice back-office url.

If you symply add the following code in the htaccess :




RewriteCond %{REQUEST_URI} ^/your_path/backend.*$

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . backend.php


RewriteCond %{REQUEST_URI} !^/your_path/backend.*$

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php

RewriteRule . index.php



you have the rules but you will get an error like ‘Unable to resolve the request’ because Yii also use the $_SERVER[‘REQUEST_URI’] var.

So to make it works you will have to remove the backend path from the $_SERVER[‘REQUEST_URI’] var.

For exemple add the following code in your backend.php :




$tmp_uri   = explode("/", $_SERVER['REQUEST_URI']);

$final_uri = "";


for($i = 0; $i < (sizeOf($tmp_uri)-1); $i++) {

	if ($i != 2)

	$final_uri .= $tmp_uri[$i].'/';

}

$_SERVER['REQUEST_URI'] = $final_uri;



for me worked something like this:

//.htaccess


RewriteRule ^/backend(.*)$ backend.php$1


RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php

//backend.php


$tmp_uri   = explode("/", $_SERVER['REQUEST_URI']);

unset($tmp_uri[0], $tmp_uri[1]);

$_SERVER['REQUEST_URI'] = implode('/', $tmp_uri);

//backend/config/main.php


'urlManager'=>array(

	'urlFormat'=>'path',

	'urlSuffix'=>'.html',

	'showScriptName'=>false,

	'baseUrl'=>'/backend',

),