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

Install SS in sub-directory, but access from TLD


Reply

7 Posts   3803 Views

Avatar
vr

8 May 2010 at 11:08am Community Member, 9 Posts

Hi,

this seems to be such a classic, found a lot of answers and none of them works 100%:

I installed SS in a sub-directory "silverstripe" of webroot just to not create a mess. Everything cool as long as I accept that the URLs go <mydomain>/silverstripe/...

I want to get rid of /silverstripe/ in the URLs. Managed for the front end, but the back end won't let me login then.
Ingredients:

One or two htaccess files, plus Director::setBaseURL("<mydomain>/"); in _config.php. What is the recommended configuration?

regards,
vr

Avatar
MarcusDalgren

9 May 2010 at 10:26am Community Member, 288 Posts

This is not possible as far as I know.

The problem is with the way SilverStripe handles requirements so when you change the baseURL the system gets all confused about where to find all the js- and css-files.

It is possible to hack path_for_file() in the Requirements class to handle the scenario of running the site from TLD but SS is installed in a subdir. I tried this myself on my Windows machine and have gotten into the CMS but everything is not perfect. It seems that, for example, the page icons for the tree menu are actually written inline so they'll have to take this into account as well.

Kindly,
Marcus

Avatar
vr

9 May 2010 at 1:37pm Community Member, 9 Posts

Hi Marcus,

thanks for your reply, usually that's where one or two htaccess files come in, to map URLs transparently for the CMS.

The problem seems to be specific to the admin section, the admin login in particular - as soon as I use SetBaseURL(<TLD>/).

As far as the front end is concerned - that part is working and looking like it was sitting in the TLD - and it must access all the subdirs with jquery etc too, in order to work.

I have seen setups for other CMSes like joomla to accomplish the same task - it can't be such an esoteric requirement ;-) Does everyone here either put their SS into webroot or, if you put it in a subdir, use a subdomain?

Regards,
vr

Avatar
MarcusDalgren

9 May 2010 at 9:32pm Community Member, 288 Posts

Hi again vr,

I agree that there should be a standard way to do this since it's a pretty common scenario and most other CMS:es (joomla, wordpress etc) offer this kind of functionality. Anyways when I set the base URL to TLD the css/javascript links in my theme stopped working as well. How exactly have you set things up right now and what version of SilverStripe are you using?

I'm running on 2.4 final and all I did was Director::setBaseURL("/"); and I moved my .htaccess to the root folder and edited it so that it pointed to the correct file. The base folder is correct but my css- and js-links end up being written as if SS has been installed in the root dir.

Kindly,
Marcus

Avatar
MarcusDalgren

9 May 2010 at 10:13pm Community Member, 288 Posts

OK I found a rather crude way of doing this. It only applies to my scenario (I think) where I'm having problems with all resource links, not just the ones in the CMS. In my .htaccess I wrote

RewriteCond %{REQUEST_URI} \.(png|gif|jp*g|ico|css|js)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) subdir/$1 [R]

where subdir is the folder that SilverStripe has been placed in. It will only act on URL:s with the file types specified on the first row and only if it's not actually a valid file. Actually thinking about it, this should hopefully work for you as well since it won't touch valid resource links, only the ones that don't work.

Try it out if you want and let me know if it works for you.

Kindly,
Marcus

Avatar
vr

10 May 2010 at 9:33am (Last edited: 10 May 2010 9:51am), Community Member, 9 Posts

Hi Marcus,

thanks, your code didn't work for me. But trying your hints I have finally found a configuration that works 100% in my setup, including the admin area. SS 2.4.0, apache, php 5.1.2 Ingredients:

- 2 .htaccess files, one in webroot and one in the "silverstripe" subdir.
- 2 entries in _config.php.

My SS subdir is called "silverstripe", please exchange that with the name of your subdir:

######## .htaccess webroot: ############

### SILVERSTRIPE START ###
<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /silverstripe/
   RewriteCond %{REQUEST_URI} !^/silverstripe/
   RewriteRule ^(.*)$ /silverstripe/$1
</IfModule>
### SILVERSTRIPE END ###

############### .htaccess silverstripe subdir: ##############

### SILVERSTRIPE START ###
<Files *.ss>
   Order deny,allow
   Deny from all
   Allow from 127.0.0.1
</Files>

<Files web.config>
   Order deny,allow
   Deny from all
</Files>

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /

   RewriteCond %{REQUEST_URI} ^(.*)$
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
</IfModule>
### SILVERSTRIPE END ###

################### _config.php: #######################
...
SiteTree::enable_nested_urls();
Director::setBaseURL("/");
...

Please give it a try and let me know if it works for you.

Regards, vr

Avatar
BuddhaSource

26 February 2012 at 11:27pm Community Member, 57 Posts

Thank you VR,

This worked for me very well :)