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

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

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

Post 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
Last edited by psy on Fri Feb 01, 2013 9:36 am, edited 4 times in total.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

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

Post 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.
mev
Power Poster
Power Poster
Posts: 371
Joined: Wed Apr 25, 2007 5:00 pm

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

Post 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
Last edited by mev on Thu May 09, 2013 1:07 pm, edited 2 times in total.
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

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

Post 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
Post Reply

Return to “Tips and Tricks”