Domain Root - CMS Link problem

Permalink
I have a *nix host and I am using .htaccess rules to redirect my primary domain to a subfolder /base which resides in /public_html simply for the sake of keeping all my sub-domain and add-on domain folders out of my concrete install directory.

When my site was simple html files, this worked and was all fine, links on my site did not show the directory my site was installed in, but now that concrete is installed, all my links look like:
http://www.mysite.com/base/index.php... where /base is the directory my site is installed in.

If I edit the /config/site.php file where DIR_REL is '/base/' and change it to '' or '/' my site does not work. I get a concrete5 formatted page that says "page not found".

I would really like to not have the install folder show in my links. My hosts forum users say this is not an .htaccess or apache problem but is an application problem.

How do I fix this?

pingram3541
 
kutis replied on at Permalink Reply
kutis
or override the document root in htaccess and point it to base dir, funny things might happen.. test thoroughly.

or just be happy with site.com/base
pingram3541 replied on at Permalink Reply
pingram3541
I am already overriding the document root in my .htaccess file and all the links work.

http://www.mydomain.com
http://www.mydomain.com/about
http://www.mydomain.com/contact

Here is my / .htaccess file:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$

RewriteCond %{REQUEST_URI} !^/base/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /base/$1

RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteRule ^(/)?$ base/index.php [L]

This redirect/rewrite is working just fine.

The problem is that C5 only works with the following line in /base/config/site.php:

define('DIR_REL', '/base');

This makes all my links look like:

www.www.mydomain.com/base/index.php...
www.www.mydomain.com/base/about...
www.www.mydomain.com/base/contact...

Of course they all work just fine and so does manually typing:

http://www.mydomain.com/about

but I should and really want to be able to hide the /base/ from the links so it's transparent.

I don't have this problem with drupal, wordpress, joomla, etc. It's an application problem, not an .htaccess problem.

Basically I think in laymans terms I need to be able to tell C5 not to incluyde the installed directory in the links and let my .htaccess rewrite do the rest.

Any suggestions?
kutis replied on at Permalink Reply
kutis
RewriteRule ^(.*)$ /base/$1
to
RewriteRule ^(.*)$ /base/index.php/$1

and set
define('DIR_REL', '')
pingram3541 replied on at Permalink Reply
pingram3541
That fixes the link problem but there is no css styling and no images. I could fix my theme to include /base/ in all the css/image request but the c5 admin has no images or css either. I wonder if a rule could also fix this? i.e. I googled wild cards in .htaccess but can't wrap my head around it. Thanks for your help.
pingram3541 replied on at Permalink Reply
pingram3541
Oh, I guess it still didn't fully work. I just realized thathttp://www.mydomain.com/ doesn't work and results in an unstyled c5 "page not found" 404 type error. But if I include the index.php eveything works as far as content and links, just no styling and images front-end or admin.
kutis replied on at Permalink Reply
kutis
the css is missing the /base/ in the path...

look into how the css is included, try editing on the fly on firefox and firebug.

if i remember correctly there is a way to add an include path to the apache, maybe can be done in htaccess as well.. and then you just need to call the css file directly without any path
stlmz replied on at Permalink Reply
I also had the same trouble as pingram3541. With said host, I have an .htaccess file in the root directory telling the main doamin to point it to a subfolder. Here is that original code:
RewriteEngine on
# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
# Change 'subfolder' to be the folder you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subfolder/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subfolder' to be the folder you will use for your main domain.
RewriteRule ^(.*)$ /subfolder/$1
# Change yourdomain.com to be your main domain again.
# Change 'subfolder' to be the folder you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
RewriteRule ^(/)?$ subfolder/index.php [L]


To correct this, change the last line by adding a "/$1" like so:
RewriteRule ^(/)?$ subfolder/index.php/$1 [L]


Hope this helps.
pingram3541 replied on at Permalink Reply
pingram3541
Thanks marquezstl! I got it working. For anyone else out there, I used the htaccess code I originally posted and then added the /$1 to the last line as marquezstl suggested.

(for some reason the original htaccess code marquezstl used for his site didn't work for mine, but adjusting the last line in the code I had previously used did work.)

I then changed the define('DIR_REL','/base'); in config/site.php where "base" is the folder my site resides in.

wooohooo!
marius replied on at Permalink Reply
marius
Hi

I have the same problem.

My .htaccess
RewriteCond %{HTTP_HOST} ^around.ch$ [OR]
RewriteCond %{HTTP_HOST} ^www.around.ch$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /around/$1 [PT,L,QSA]

Redirect my URLhttp://www.around.ch to the subfolder /around.

Now when i open a C5 Site the URL look like this:http://www.around.ch/around/about

I tryed to change the define('DIR_REL', '/around'); but it doesn't work.

I tryed the example above but it doesn't work :-|

Can someone help me? Thank you.

marius
Remo replied on at Permalink Reply
Remo
it looks like you've installed c5 in a subdirectory, right?

In this case you have to set RewriteBase to /around

Or just use the .htaccess file content which you get when you activated the pretty urls in the sitewide settings
marius replied on at Permalink Reply
marius
Hi remo

yes C5 is in a subdirectory.

Doesn't work with the .htaccess from the pretty urls.

The URLhttp://www.around.ch/about/ works but all links are:

http://www.around.ch/around/about/...

When i edit the site.php
define('DIR_REL', '/around'); to
define('DIR_REL', '');

An C5 error site appears

strange.

gruess us Lozern
marius replied on at Permalink Reply
marius
When i change define('DIR_REL','/around') to ('DIR_REL','') all pages work except the home.

http://www.around.ch/ -> doesn't work
http://www.around.ch/about -> works
marius replied on at Permalink Reply
marius
other solution, i change the redirection to home. But in which file can i find the redirection to the home?

I have searched in url_check.php, dispatcher.php, base.php? I would to change it to an other subsite.

Thanks for any help
commandnotapple replied on at Permalink Reply
commandnotapple
Okay folks, I've toyed with .htaccess unsuccessfully for over 6 hours now. I installed Concrete into a sub directory and wish it to be removed or be made invisible (obviously, or I wouldn't be posting this).

Concrete is installed in the directory "Concrete":

anthonygarritano.com/Concrete

My site works, all URLs work. But they all reference /Concrete:

anthonygarritano.com/Concrete/about
anthonygarritano.com/Concrete/contact

Also, manually typing without /Concrete works:

anthonygarritano.com/contact
anthonygarritano.com/about

I have no idea how to get rid of /Concrete. Here is my .htaccess file:

Options -Indexes
Options +ExecCGI 
AddHandler fastcgi-script fcg fcgi fpl 
AddHandler php5-fastcgi .php 
Action php5-fastcgi /cgi-bin/dispatch.fcgi 
# Turn on rewrites.
Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(http://)?anthonygarritano.com$
RewriteCond %{REQUEST_URI} !^/Concrete/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /Concrete/$1
RewriteCond %{HTTP_HOST} ^(http://)?anthonygarritano.com$
RewriteRule ^(/)?$ Concrete/index.php/$1 [L]


I posted the whole .htaccess for kicks, but obviously the important stuff is where RewriteEngine on is.

ANY help, tips, advice, or links are appreciated. I'm a n00b, so play nice and over explain things please (plus, posterity will appreciate this ;)!
commandnotapple replied on at Permalink Reply
commandnotapple
Okay folks, I've toyed with .htaccess unsuccessfully for over 6 hours now. I installed Concrete into a sub directory and wish it to be removed or be made invisible (obviously, or I wouldn't be posting this).

Concrete is installed in the directory "Concrete":

anthonygarritano.com/Concrete

My site works, all URLs work. But they all reference /Concrete:

anthonygarritano.com/Concrete/about
anthonygarritano.com/Concrete/contact

Also, manually typing without /Concrete works:

anthonygarritano.com/contact
anthonygarritano.com/about

I have no idea how to get rid of /Concrete. Here is my .htaccess file:

Options -Indexes
Options +ExecCGI 
AddHandler fastcgi-script fcg fcgi fpl 
AddHandler php5-fastcgi .php 
Action php5-fastcgi /cgi-bin/dispatch.fcgi 
# Turn on rewrites.
Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(http://)?anthonygarritano.com$
RewriteCond %{REQUEST_URI} !^/Concrete/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /Concrete/$1
RewriteCond %{HTTP_HOST} ^(http://)?anthonygarritano.com$
RewriteRule ^(/)?$ Concrete/index.php/$1 [L]


I posted the whole .htaccess for kicks, but obviously the important stuff is where RewriteEngine is.

ANY help, tips, advice, or links are appreciated. I'm a n00b, so play nice and over explain things please (plus, posterity will appreciate this ;)!
marius replied on at Permalink Reply
marius
At the moment "not" possible.

All in all, it's too much hassle to figure out where the problem is. Put your site back to the root domain.

It's on the bug list:
http://www.concrete5.org/community/bugs/domain_redirect_to_subfolde...

sorry greez

marius
chassa2556 replied on at Permalink Reply
chassa2556
Can't seem to make this work. If my domain was called 'charlie.com' and my concretecms was in a directory called 'concrete'.

The root index.htm file is in the home directory called 'www'.

So I want to cloak the directory 'concrete' but want to route to the index.php in this directory.

How would you then set the code?
cannonf700 replied on at Permalink Reply
cannonf700
Here's what I did to make my work:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$
RewriteCond %{REQUEST_URI} !^/base/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /base/index.php/$1
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$
RewriteRule ^(/)?$ yourdomain.com/index.php/$1 [L]

where obviously 'yourdomain.com' is your domain and 'base' is the subfolder where your c5 site is installed.
Thanks everyone for posting to this thread. There's no way I could have made this work without everybody's input.
webjedi replied on at Permalink Reply
webjedi
I think I would rather physically MOVE my concrete subfolder to root.

Its hopefully a snap and just an adjustment to the concrete5/config/site.php file...


*** UDPDATE ***

Easily moved to root, changed one line of code, URLS look fantastic on Godaddy.
Shotster replied on at Permalink Reply
Shotster
So you're saying you have your C5 installation within a subfolder called "base" and that you've modified DIR_REL in "site.php" to be "/base" and that "base" does not show up in the site links/URLs generated by C5?

-Steve
Shopimport replied on at Permalink Reply
Shopimport
I got it working with Concrete5 version 5.4.0.

I have setup Concrete5 in the subfolder /cms. In /cms/config/site.php I do have
define('DIR_REL', '');
So no DIR_REL.

In the root I do have /.htaccess also mentioned earlier in this forum:
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line - RewriteEngine on
RewriteEngine on
# Change yourdomain.com to be your main domain.
#RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$
# Change 'subfolder' to be the folder you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/cms/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subfolder' to be the folder you will use for your main domain.
RewriteRule ^(.*)$ /cms/$1 
# Change yourdomain.com to be your main domain again.

Ensure the last slash behind index.php is there! By the way, this forum might not show all lines, so press 'view entirely code block'.

So far I got pages working likehttp://www.yourdomain.com/about however still the home page reported "Page Not Found,No page could be found at this address".

To correct this behaviour, edit the concrete/libraries/request.php and change this around line 77:

if (!$path) {
  $path = Request::parsePathFromRequest('SCRIPT_NAME');
}

into
if ($path === false) {
  $path = Request::parsePathFromRequest('SCRIPT_NAME');
}

The root cause is that the PATH_INFO already nicely found the correct path, however the $path returned is empty '' and in php you should then explicity test for false. So might be reported as a bug?

To enable pretty URL I have created /cms/.htaccess with the following content:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cms/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>


Then I made sure not to have a /index.php in the root! When you do so it might not work for the edit mode! Concrete5 loads the menu bar by something like:

http://www.yourdomain.com/index.php/tools/required/page_controls_me...

So if the root /index.php is existing it will not rewrite the url to /cms/index.php (due to the line RewriteCond %{REQUEST_FILENAME} !-f)

I just got working properly and so far I didn't see sideeffects
Shopimport replied on at Permalink Reply
Shopimport
I now did notice a sideeffect and found a working solution.

With my above mentioned changes I was able to edit pages when the URL contains friendly URL's likehttp://www.yourdomain.com/about however it failed on direct pages like when you visit you page via the dashboard -> site manager. It tries to openwww.www.yourdomain.com/index.php?cID=66... and will get display the Page Not Found message.

To also correct this issue I noticed that also PATH_INFO will not be available and returns false on
$path = Request::parsePathFromRequest('PATH_INFO');

And then it will call
$path = Request::parsePathFromRequest(SCRIPT_NAME');
however SCRIPT_NAME contains the subfolder again (so /cms/index.php).

To prevent SCRIPT_NAME from doing this I just disabled it.

In my post above I mentioned this code:
if (!$path) {
  $path = Request::parsePathFromRequest('SCRIPT_NAME');
}

Now replace this part into:
if ($path === false) {
  $path = "";
}

Be aware that this is only properly working when the site will be or will act like it's in the root. So together with the root /.htaccess.
voxbaryton replied on at Permalink Reply
Would appreciate it if any of you could address my problems here:

http://www.concrete5.org/index.php?cID=98018...
dallyhorton replied on at Permalink Reply
dallyhorton
I just wanted to post a huge thanks for your post Shopimport. I spent hours trying to solve this problem until coming across your solution. Worked perfectly for me.
klm1 replied on at Permalink Reply