Page 1 of 1

Install CMSMS in a subdir and still use www.mydomain.com

Posted: Tue Jan 15, 2013 12:02 pm
by psy
This took a bit of research as is not my area BUT I got it working, ie install CMSMS in a sub directory and still access it using a 'TLD', top level domain name.

Firstly, install CMSMS as normal in a sub directory, eg:

Code: Select all

http://www.mydomain.com/cms
using the default htaccess.txt file renamed to .htaccess.

You'll now be able to access the site using "http://www.mydomain.com/cms".

Next, create an .htaccess file in the ROOT directory that contains:

Code: Select all

# force www IN URL
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
# END force www IN URL 


RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule !^cms(/?|/.+)$ /cms%{REQUEST_URI} [L]

What this does is force the domain name to be prefixed by www - needed for admin functions and stylesheets.

It then rewrites the URL to "http://www.mydomain.com" and points to the 'cms' directory.

I'm sure there are many other solutions but my research in this forum came up with lots of broken links. Just putting it out there for anyone who wants it.

Hope this helps
psy

Re: Install CMSMS in a subdir and still use www.mydomain.com

Posted: Sat Jan 19, 2013 1:09 pm
by psy
One more thing once you've done the above.

Add the following to config.php

Code: Select all

$config['root_url'] = "www.mydomain.com";
The .htaccess files will take care of the rest.

Re: Install CMSMS in a subdir and still use www.mydomain.com

Posted: Tue Apr 30, 2013 3:44 pm
by mev
Thanks for writing this down Psy !
It didn't work in one of my sites in a subdir, unfortunately!
Are you sure there isn't a typo somewhere?

I used another method:

1.in the www-root an index.html including a meta-refresh to redirect to the subdir;

2. in the www-root I put the .htaccess with the following code:

Code: Select all

DirectoryIndex index.html index.php
Options -Indexes
RewriteEngine On
RewriteOptions inherit

# if it's not a real file
RewriteCond %{SCRIPT_FILENAME} !-f
# rewrite to the subdirectory
RewriteRule !^CMS(/?|/.+)$ /CMS%{REQUEST_URI} [L]
3.
Initially, I had put this code in the config.php in the subdir:

Code: Select all

$config['root_url'] = "http://www.website.com";
However in that case I couldn't reach the admin anymore. So deleted that.
So, still got the name of the sub-dir visible inside the urls of all pages, except for the Homepage.

CORRECTION:
There was something else in the way, which appeared to be the reason why it did not work. My error!!
Sorry psy. It works very well now, very many thanks!

willemijn

Re: Install CMSMS in a subdir and still use www.mydomain.com

Posted: Wed May 01, 2013 4:52 pm
by blackhawk
Thanks psy for the steps. I'm also having an issue. I can see in Google Chome, through developer tools, that all my links and scripts in my <head> have been modified, but my main URL for the site is still showing as a sub directory location. So something must be missing from these steps if you have it working on your end.

FYI - I tried this locally on my desktop machine with one of my virtual directories called -

Code: Select all

http://dev.mdt/dev/
...the location of my cmsms site and I'm trying to get it to show without the /dev at the end.

Thanks so far for the idea.

blackhawk