Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Installing SilverStripe /

Getting SilverStripe up and running on your computer and on your web server.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

RewriteBase directive in .htaccess and url with spaces


Reply


3 Posts   3419 Views

Avatar
Myrdhin

Community Member, 67 Posts

31 December 2009 at 5:08am

Edited: 31/12/2009 12:37pm

Hello,

I had a problem with my installation :

  • SilverStripe 2.3.4
  • installation directory : /var/www/my directory/silverstripe-2.3.4/

The problem was that "install.php" created a .htaccess file with this directive :

RewriteBase /my directory/silverstripe-2.3.4/

But, spaces in the url (like in "my directory") isn't supported.

To resolve the problem, i've changed by :

RewriteBase /my%20directory/silverstripe-2.3.4/

If you want, there is the modification to add in the install.php file (in the function createHtaccess, line 875) :

867: function createHtaccess() {
868: $start = "### SILVERSTRIPE START ###\n";
869: $end = "\n### SILVERSTRIPE END ###";
870:
871: $base = dirname($_SERVER['SCRIPT_NAME']);
872: if(defined('DIRECTORY_SEPARATOR')) $base = str_replace(DIRECTORY_SEPARATOR, '/', $base);
873: else $base = str_replace("\\", '/', $base);
874:
====> 875: $base = str_replace(' ', '%20', $base);
876:
877: if($base != '.') $baseClause = "RewriteBase $base\n";
878: else $baseClause = "";

Avatar
Myrdhin

Community Member, 67 Posts

31 December 2009 at 1:07pm

Boooo :'(

Now i can see my web site but i can't login in the administration interface...

I think it's a problem with spaces in URL because if i delete spaces (and modify the RewriteBase directive in my .htaccess file to delete spaces in URL), i can login without problem !

Does Silverstripe have problem with spaces in url ? I think.

Avatar
Myrdhin

Community Member, 67 Posts

31 December 2009 at 1:39pm

I think i resolved my problem... But i don't know if it's the best solution because i'm a beginner in SilverStripe php code.

So, i modified the "sapphire/core/control/Director.php" file, line 417, in "baseURL" method.
I added this line :

$baseURL=str_replace(' ', '%20', $baseURL);

Now, my baseURL method is

static function baseURL() {
if(self::$alternateBaseURL) return self::$alternateBaseURL;
else {
$base = dirname(dirname($_SERVER['SCRIPT_NAME']));
if($base == '/' || $base == '/.' || $base == '\\') $baseURL = '/';
else $baseURL = $base . '/';

$baseURL=str_replace(' ', '%20', $baseURL);

if(defined('BASE_SCRIPT_URL')) return $baseURL . BASE_SCRIPT_URL;
else return $baseURL;
}
}

Now i can login in admin interface.