Hide the subdirectory URL

Permalink 2 users found helpful
Okay, so I've gone through all 136 pages on this forum. I still haven't found a total solution, even though I'm pretty sure my problem is fairly common. Basically, I have installed concrete5 to a subdirectory /cms under the directory I am using for my root. I want my URLs to not show the /cms. I know that my .htaccess is set up properly for this, now my only problem is that concrete5 keeps re injecting the /cms into all the links, probably due to the DIR_REL variable in site.php.

So what I'm looking for is:
1) install concrete5 in a subdirectory, /cms
2) force concrete5 to act like it is installed at root with a blank DIR_REL
3) pretty urls

To make things more complicated I'm using bluehost which is notorious for not putting the main domain under its own subdirectory, and I have to use .htaccess hackery to make a directory under the root act like it was the root. I'm pretty sure that this means I have to merge the .htaccess in the document root with the suggestions for pretty URLs since the requests are actually hitting the document root first, and then getting rewrites to the actual subdirectory the site is in.

I'm pretty sure that my .htaccess is right in this case.

So the actual directory structure to concrete5 is /public_html/*fakeroot*/cms/(concrete5files)

and again I want concrete5 to act as if the cms part of the path is not there at all.

So far the closest post that addresses this issue is herehttp://www.concrete5.org/community/forums/customizing_c5/domain_roo...


And with the hacking of request.php I am tantalizingly close to what I want, however none of my CSS or images show up properly.


Please, please, please help.

Below is my .htaccess file.

# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
# Turn off mod_dir generated directory listings.
Options -Indexes
# Turn off mod_dir generated trailing slash redirects.
DirectorySlash Off
# Default index files. NOTE: Does not work for /. See below.
DirectoryIndex index.html index.php
# Custom errors to hide primary domain subdirectory.
ErrorDocument 403 /403.php
ErrorDocument 404 /404.php
#Turn on the rewrite engine.
RewriteEngine On
# Redirect from domain.name tohttp://www.domain.name first.
RewriteCond %{HTTP_HOST} ^manifoldthought\.net$ [NC]

 
Mnkras replied on at Permalink Reply
Mnkras
well, what you can try doing, as a simple thing (havn't tried it) is copy the index.php to the /public_html modify the path in that file to include the /cms then changing the site.php
voxbaryton replied on at Permalink Reply
All right, finally figured it all out. You do have to use the hack on request.php the earlier link I posted contains in order to keep concrete5 from looking up the wrong path even when everything is set correctly in .htaccess and DIR_REL is set to empty.

However after doing that css/images/god knows what else will be broken. The reason for this is that most things are generated by concrete5 dynamically through the index.php file, but a few things are actual static files that exist under the directory structure. The usual .htaccess rules will rewrite the urls for the static resources to go through index.php like everything else, and concrete5 will be hitting the database expecting to find content instead of letting the server find the static files. A good way to illustrate this is to try to pull up the url for the concrete5 logo in the upper left hand directly (which should be missing if this is happening to you, but you should still be able to right click and grab the url) and you'll see that instead of getting a server 404 page you get a concrete5 specific 'page not found' error which indicates that index.php actually tried looking for content in the database and of course failed.

To fix this you need to add two lines to .htaccess to exclude anything that already exists first. This should go before your rule that rewrites calls to the index.php, wherever it's located,

#Concrete5 serves static things out of its own directory,
#We don't want to go through index.php in those cases.
RewriteCond %{DOCUMENT_ROOT}/<path to concrete>/%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}/<path to concrete>/%{REQUEST_URI} !-d


But this is only good enough to ignore static files that exist. You need a new rewrite rule as well to fix the url if you're hosting concrete5 out of a subdirectory (or two)

RewriteCond %{DOCUMENT_ROOT}/<path to concrete>/%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/<path to concrete>/%{REQUEST_URI} -d
RewriteRule ^(.*)$ /<path to concrete>/$1


Note that there are no ! here because this time the rule kicks in if the files exist not if they do not exist which was done last time to exclude them.


I was trying to get this method to work all day yesterday, what I didn't realize is that I needed to use the %{DOCUMENT_ROOT} variable in order to check the right path.

I'll probably make a HowTo post that pulls everything together with a generic .htaccess for people to use if I have the time.
jincmd replied on at Permalink Reply
jincmd
could you post full instructions?
dallyhorton replied on at Permalink Reply
dallyhorton
Thanks for posting these instructions voxbaryton. I think there would be a lot of people that would appreciate a good How To, myself included.
ighc5 replied on at Permalink Reply
Here's an alternative way to achieve this assuming the site ishttp://www.example.com and Concrete5 is in the c5 subdirectory which you want to hide in the url.

/.htaccess - in the site root directory
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Add trailing slash if path does not contain a period or end with a slash
RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule (.*) http://www.example.com/$1/ [R=301,L]
#Changehttp://example.com tohttp://www.example.com (Optional)
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^/?(.*)$ http://www.example.com/$1 [R=301,L]
#Rewriteshttp://www.example.com/ tohttp://www.example.com/c5 except for directories we want normal access to
RewriteCond %{REQUEST_URI} !^/c5
# exclude other sub-directories if necessary
RewriteCond %{REQUEST_URI} !^/testphp
RewriteCond %{REQUEST_URI} !^/plesk-stat
RewriteRule ^(.*)$ c5/$1 [L]



/c5/.htaccess (if pretty urls are enabled)
# -- concrete5 urls start --
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
# -- concrete5 urls end --


Edit config/site.php and define another DIR_REL2. DIR-REL will be the url subdirectory (empty)
and DIR_REL2 will be the server subdirectory (c5)
define('DIR_REL', '');
define('DIR_REL2', '/c5');
define('ENABLE_CMS_FOR_PATH', '');


Edit concrete/libraries/request.php and
change DIR_REL to DIR_REL2 in the parsePathFromRequest functon.

Note. remember to re-apply this change every time you upgrade concrete5.
private static function parsePathFromRequest($var) {
       $path = (isset($_SERVER[$var])) ? $_SERVER[$var] : @getenv($var);
       if (!$path) {
          return false;
       }
       // if the path starts off with dir_rel, we remove it:
       if (DIR_REL2 != '') {
          $dr = trim(DIR_REL2, '/');
          $path = trim($path, '/');
          if (strpos($path, $dr) === 0) {
             $path = substr($path, strlen($dr));    
          }
       }
       $path = trim($path, '/');
       if (strpos($path, DISPATCHER_FILENAME) === 0) {
Gertjan replied on at Permalink Reply
Thanks at lot! I read and tried a lot of suggestions on this forum but this solution is sound and clear. Works like a charm.
widydesain replied on at Permalink Reply
I totally agree.it worked like a charm.Thanks
PatrickHeck replied on at Permalink Reply
PatrickHeck
Thanks for this ighc5! I think you should also post this in the howto section.

Patrick
ighc5 replied on at Permalink Reply
Thanks Patrick, that's a good idea. I've just submitted it awaiting approval.

Ian
olavax replied on at Permalink Reply
Hello,

Thank you very much for this details, however I'm a bit puzzeled, i'm running a Version 5.5.1, the site is running perfectly but I cant find conc/libraries/request.php file.

I guess that a change happened in this area of concrete5 from the version on which you suggest your changes.

Could someone propose that same level of details for subdir hidding in 5.5.1 ?

Thanks a million.

(c5.x.y beginer fan)

BTW: I cant figure out where to find the reference of the running verion in the dashboard ;O) any idea ?)
ighc5 replied on at Permalink Reply
This still applies for 5.5.1. request.php is in concrete/libraries off the directory where you installed concrete5.

To view version levels etc. go to Dashboard > System & Settings > Environment Information

Ian
olavax replied on at Permalink Reply
Sure ! and many thanks !

it was'nt in the subdirectory I was looking for :
- \www\conc\concrete\libraries <-- is good
instead of
- \www\conc\libraries <-- is wrong :o)

Now, I did the updates, however I face some changes regarding the look : The page where I defined a layout of the via blocks has lost its structure and the "expand and colapse" block of the marketplace doesnt work any longer : they are displayed open and can't be close despide the setting.
In addition the administration has disapear !!

- any idea where I have to look to fix this ?

Beside this,
I'm using iframe block with an external gallery generated by jAlbum inside. Of course this dosent work any longer. I'll have some DIY in www\.htaccess to do I suppose ?

,.-~*´¨¯¨`*·~-.¸-(_NEWS NEWS _)-,.-~*´¨¯¨`*·~-.¸

After many test at the limits of my skills (!) I reinstall C5 elsewhere, then the themes (rigidlight) and addons. Finally I import the database (some pictures has gone) and this stands as I wish....
As if the theme and addon didnt support to have the directory changed after being install which would be very surprising... any exlanation ?
TaylorG replied on at Permalink Reply
I've just tried this and I seem to have made some sort of error. Now I just get the error below when I go to my site.

Any guesses where I went wrong?

An unexpected error occurred.
mysql error: [2006: MySQL server has gone away] in EXECUTE("select tpID, tpHandle, tpName, tpDescription, pkgID from TaskPermissions where tpHandle = 'view_newsflow'")
An unexpected error occurred.
mysql error: [2006: MySQL server has gone away] in EXECUTE("insert into Logs (logType, logText, logIsInternal) values ('exceptions', 'Exception Occurred: mysql error: [2006: MySQL server has gone away] in EXECUTE("select tpID, tpHandle, tpName, tpDescription, pkgID from TaskPermissions where tpHandle = \'view_newsflow\'")\n\n#0 /home/taylgil9/public_html/cms/concrete/libraries/3rdparty/adodb/adodb.inc.php(1037): adodb_throw(\'mysql\', \'EXECUTE\', 2006, \'MySQL server ha...\', \'select tpID, tp...\', false, Object(ADODB_mysql))\n#1 /home/taylgil9/public_html/cms/concrete/libraries/3rdparty/adodb/adodb.inc.php(993): ADOConnection->_Execute(\'select tpID, tp...\')\n#2 /home/taylgil9/public_html/cms/concrete/libraries/3rdparty/adodb/adodb.inc.php(1605): ADOConnection->Execute(\'select tpID, tp...\', Array)\n#3 /home/taylgil9/public_html/cms/concrete/models/task_permission.php(68): ADOConnection->GetRow(\'select tpID, tp...\', Array)\n#4 /home/taylgil9/public_html/cms/concrete/models/task_permission.php(200): TaskPermission::getByHandle(\'view_newsflow\')\n#5 /home/taylgil9/public_html/cms/concrete/helpers/concrete/interface.php(154): TaskPermission->__call(\'canViewNewsflow\', Array)\n#6 /home/taylgil9/public_html/cms/concrete/helpers/concrete/interface.php(154): TaskPermission->canViewNewsflow()\n#7 /home/taylgil9/public_html/cms/concrete/elements/header_required.php(96): ConcreteInterfaceHelper->showNewsflowOverlay()\n#8 /home/taylgil9/public_html/cms/concrete/libraries/loader.php(116): include(\'/home/taylgil9/...\')\n#9
TaylorG replied on at Permalink Reply
Nevermind . . . it seems to have fixed itself. That's odd. I suppose it just needed some time to sort out the new settings or something. I honestly have no idea.
kirkroberts replied on at Permalink Reply
kirkroberts
Thanks so much for posting this. I have a client on Bluehost where we want to put the main domain in a subdirectory and I *almost* have this working.

EDIT: it's working. I had neglected to update the subfolder name in site/config.php

That said, in /SUBFOLDER/(updates/concrete5.5.2.1/)concrete/libraries/required.php the parsePathFromRequest function has changed, putting the DIR_REL in a switch statement:

private static function parsePathFromRequest($var) {
      $path = (isset($_SERVER[$var])) ? $_SERVER[$var] : @getenv($var);
      if (!$path) {
         return false;
      }
      switch ( $var ) {
         case 'PATH_INFO':
            // DIR_REL not in path; do nothing.
            break;
         case 'REQUEST_URI':
            $path = str_replace($_SERVER['QUERY_STRING'], '', $path);
            $path = trim($path, '?');
         default:
            // if the path starts off with dir_rel, we remove it:
            if (DIR_REL != '') { // this would be changed to DIR_REL2


Seems that just changing DIR_REL to DIR_REL2 works.
kirkroberts replied on at Permalink Reply
kirkroberts
It's working now. My mistake. Post updated above.
klm1 replied on at Permalink Reply
DTriplett replied on at Permalink Reply
Here is yet another way to do this that just adds a single modified index.php to your site, without changing .htaccess:
Install to a Subdirectory, Run from root (without patches or .htaccess)
http://www.concrete5.org/?cID=612245...
MortQ replied on at Permalink Reply
Does anyone know if there is a working link to this solution? http://www.concrete5.org/?cID=612245...
It keeps coming up in searches, but this link appears to be dead, just seems to go to a log in page, and logging in does nothing.