Base url weirdness - logging in with www prefix results in buggyness


I've defined my base url in the config like so:

define('BASE_URL', '');
define('REDIRECT_TO_BASE_URL', false);

And as you can see I am using REDIRECT_TO_BASE_URL = false

Now, if I then log in via. everything is seemingly OK up untill the point I add a new page via. the sitemap. What I then get is a redirect to the base url (no www) - and now the system thinks I'm not logged in.

Hence adding the page fails.

For novice users this is quite confusing and nonsensical. It seems to me this is a bug in C5 - but I haven't been able to dig up any info on this.... Any thoughts and ideas out there?

View Replies: View Best Answer
kirkroberts replied on at Permalink Reply
It might be helpful to read what your desired behavior is, and also why.
For instance, why would you use a base url that you don't want to redirect to?
Why not just set up the base url with the www and allow the redirect?

What version of Concrete5 are you using?
Hammertime replied on at Permalink Reply
Hi Kirk,

I'd like to note that I am not a newbie to C5 and have been developing for the platform for over a year now, and set up dozens of sites with all sorts of custom code.

I think ever since v5.4.1.1 I started noticing this behavior - but I never investigated it further as I knew how to work around it (just log in via. the same url as defined in my base url and everything is fine)

The other day we got a very upset customer due to this however, and I then decided to look into this further. Now, I thought this was the appropriate forum to post this in - but this place seems to be filled to the brim with inane questions regarding the base url setting, so maybe I'm not coming across properly. In any case, what I am getting at is that I understand perfectly how the base url config works, and what it does. I am 99% certain that what I am seeing here is a bug in C5 - and I would like to either work around it, or maybe get feedback on whether it is fixed in the upcoming version.

To distill the problem to its bare essence:

*) With redirect to base url = false this problem manifests itself
- Basically what happens is that at certain points the C5 core code doesn't take this constant into account and does a redirect in anyway.

With redirect = true - you of course get a redirect to the base url as soon as the user wants to log in, so this problem never shows.

However, we want redirect=false, as this enables us to have an alternate domain pointing in to the site during development (and in the transition period between users buying a domain name and everything going live)

Now, I could of course just go in and change redirect to = true whenever we've finally launched a site - but I'd like to avoid that if possible.

I'm not sure if I can get more concise than this. The critical points in time where C5 redirects, when it really shouldn't is:

1) Adding a new page via. the sitemap
2) Clicking the Edit Page button in the Front-end editor

Maybe this should be moved to Beta-bitching? Although that doesn't seem like the 100% appropriate place for this question....

kirkroberts replied on at Permalink Best Answer Reply
Yeah, sounds like you've uncovered something! It would be great if you took a minute to submit your findings to the bug tracker.

In the meantime, here's a snippet I use often that I got from a c5 team member to allow one config to control your site in multiple locations.
In /config/site.php use this:
$hostname = $_SERVER['HTTP_HOST'];
if (trim(strtolower($hostname)) == "") {
   // local info
   define('DB_SERVER', '');
   define('DB_USERNAME', '');
   define('DB_PASSWORD', '');
   define('DB_DATABASE', '');
   define('PASSWORD_SALT', '');
   define('DIR_REL', '');
   define('BASE_URL', 'http://' . $hostname);
} else {
   // site info
   define('DB_SERVER', '');
   define('DB_USERNAME', '');

Obviously you have to put in your own details, and you can use a switch instead and have as many options as you want (ie a "www" version, a non-www version, a staging area, a local address, etc). This might help you get around having to fuss with the "no redirect" thing... which I have to admit I hadn't known about previously!

Hope that helps!
Hammertime replied on at Permalink Reply
Hi Kirk,

Wow, yeah nice solution there! I hadn't thought of that... i.e. dynamically loading a config based on the domain name. Very clever.

I'll certainly use this approach on future sites :)

Also, I'll throw in a note in the bug tracker and see what happens. Thanks for your time, dude!

Arni J
kirkroberts replied on at Permalink Reply
You're welcome!
I've found that trick VERY handy and infinitely flexible. So nice to not have to change the config in different environments.
prestressed replied on at Permalink Reply
Hi, sorry but I have only 24 hours experience of concrete so am v new here (though impressed so far). I have just transferred a small existing flat html site to concrete, with some success. However, all my URLs appear as whereas I would prefer as the default if possible. (I changed the base URL to include www, it didn't seem to do anything?)

It looks like I might be able to use some of the code described here to accomplish this via the config?? But not sure quite how??

Also, my site pages are all currently indexed on Google as, for example,
Now I have concrete-ised the site, mypage1.htm has become just mypage1
Can I get some sort of redirect set up within Concrete, or would I have to republish the html pages myself with individual redirects?

Would be most grateful for any help.
kirkroberts replied on at Permalink Reply
Including the 'www' in your BASE_URL definition *should* do the trick.
define('BASE_URL', '');

If that isn't working, double check that your updated config/site file is on the same server you're testing on. Your config might be right, but not in the right place :-)

Not sure about the best way to preserve your .htm search engine rankings.
To my knowledge you can't enter a file extension in the c5 page paths.

You could write an htaccess redirect/rewrite to handle that. I'd take a moment to explore that option rather than publishing blank files with redirects.
prestressed replied on at Permalink Reply
thank you Kirk. You were 100% correct, my config was not in the right place...
and it was certainly looking as if I couldn't enter file extensions in the page paths (c5 just changed any dots to hyphens) so I'll go with the htaccess solution as suggested.
Much appreciated!
kirkroberts replied on at Permalink Reply
You're welcome! Glad you got it figured out, and good luck with the htaccess.