Url appearance question

drding

New Member
I recently set up a new site on a new host that isn't the same company the domain names are registered at. I'm used to linking to hosts through their name servers, but this time around in order to keep the emails working (they are at the same company the domains are registered at) we ended up having to link up to the new host by the A record of the server.

Now I don't know if this is related to the way we set this whole thing up, but I noticed the url to the site is listing as: www.someexample.com/~username

And where username is in that url, is the username on the account for our host.

Also for example if you went to another page it would look like this: www.someexample.com/~username/somepage.html

Is that normal? Is it because we linked up through the A records rather then name servers?

Is there anyway to get rid of the "~username" part?
 

chrishirst

Well-Known Member
Staff member
Is that normal? Is it because we linked up through the A records rather then name servers?
Yes and No.

It actually means the site is not setup correctly at the host.
 

chrishirst

Well-Known Member
Staff member
No I mean something is badly setup in httpd.conf, I would guess that the hosting company have added a redirect to the Apache mod_userdir alias (http://server/~username)

IF the hostname (site.tld) is correctly configured in httpd.conf all request should go to the document root of /home/username/public_html/ and the only reason a request would go to the user alias is if that is how it is setup.

There is ABSOLUTELY NO DIFFERENCE in using DNS at the registrar or using DNS on the host company, in your registrar DNS control panel you should have the 'A' record set for the server IP along with a CNAME for the 'www' pointing to site.tld.

Have you run nslookup (Windows) or a 'dig' (Mac/Linux) against the domain to see what is returned?
 

drding

New Member
This is a bit more advanced then what I'm knowledgeable of but I just ran a nslookup on the domain and it's showing the same IP that we used for the A record setup at the domain registry.

What's odd is I can get to the site fine with the straight up domain minus the ~username part.

And then the ~username gets added when I click the script generated home link from the CMS we're using. That link, when you hover over it is listed as the www.someexample.com/~username

Which got me thinking it might have something to do with how the CMS was set up. I'd like to ask about it over at their forum just to cross it off as a possibility.

Does that sound like it could be it to you? The CMS by the way is Modx.
 

chrishirst

Well-Known Member
Staff member
What's odd is I can get to the site fine with the straight up domain minus the ~username part.
by using the website registered URL? (site.tld)

Which got me thinking it might have something to do with how the CMS was set up

Yep that will be it, I'd suggest that it was setup using the mod_dir name before the DNS was fully resolved.


Open core/config/config.inc.php in a text editor and change the $http_host to the correct URL.
 

drding

New Member
Open core/config/config.inc.php in a text editor and change the $http_host to the correct URL.

Yep it's accessible from the site.tld

Thanks for the confirmation! Ok so I took a look at the file you mentioned, and I think it's this string of code:

Code:
if (!defined('MODX_HTTP_HOST')) {
    if(defined('PHP_SAPI') && (PHP_SAPI == "cli" || PHP_SAPI == "embed")) {
        $http_host='[B]my url here?[/B]';
        define('MODX_HTTP_HOST', $http_host);
    } else {
        $http_host= $_SERVER['HTTP_HOST'];
        if ($_SERVER['SERVER_PORT'] != 80) {
            $http_host= str_replace(':' . $_SERVER['SERVER_PORT'], '', $http_host); // remove port from HTTP_HOST
        }
        $http_host .= ($_SERVER['SERVER_PORT'] == 80 || $isSecureRequest) ? '' : ':' . $_SERVER['SERVER_PORT'];
        define('MODX_HTTP_HOST', $http_host);
    }
}

I bolded where I believe you're saying it should go, but I wanted to make sure.
Also, do I need to change any of the other urls in the file? Like any of the ones linking to certain files or folders the CMS needs?

Like for example, the url to the assets folder is set up like this right now:

Code:
if (!defined('MODX_ASSETS_PATH')) {
    $modx_assets_path= '/home/hostusername/public_html/assets/';
    $modx_assets_url= '/[B]~hostusername[/B]/assets/';
    define('MODX_ASSETS_PATH', $modx_assets_path);
    define('MODX_ASSETS_URL', $modx_assets_url);
}

Like that bolded bit above, do I need to fix that path and others like it?
 

chrishirst

Well-Known Member
Staff member
This line sets the host name directly from the HTTP request
PHP:
$http_host= $_SERVER['HTTP_HOST'];
so whatever is used to request the website will be set base URL for the whole session, which can cause canonical issues with ModX and search engines, if you replace the server request variable with a fixed value it will always respond on that URI.
 

drding

New Member
Incoming dumb question...

Can I define that variable near the start of the config file where the other variables are defined, basically with a:

Code:
$http_host='www.mydomainname.com';

I'm probably way off base here.
 

chrishirst

Well-Known Member
Staff member
Yes you can, BUT you will also have to disable (comment out) the code that that sets it to the HTTP_HOST value, otherwise it will overwrite your settings.
 

drding

New Member
I tried it out and I think I'm commenting out the wrong part of the script, I did clear out my cache folder just in case too.

Here's part of my config file with confidential parts removed and/or edited. Could you point out which part I should comment out? I really appreciate all the assistance so far, you've been a huge help.

Code:
if (!defined('MODX_CORE_PATH')) {
    $modx_core_path= '/home/username/public_html/core/';
    define('MODX_CORE_PATH', $modx_core_path);
}
if (!defined('MODX_PROCESSORS_PATH')) {
    $modx_processors_path= '/home/username/public_html/core/model/modx/processors/';
    define('MODX_PROCESSORS_PATH', $modx_processors_path);
}
if (!defined('MODX_CONNECTORS_PATH')) {
    $modx_connectors_path= '/home/username/public_html/connectors/';
    $modx_connectors_url= '/~username/connectors/';
    define('MODX_CONNECTORS_PATH', $modx_connectors_path);
    define('MODX_CONNECTORS_URL', $modx_connectors_url);
}
if (!defined('MODX_MANAGER_PATH')) {
    $modx_manager_path= '/home/username/public_html/manager/';
    $modx_manager_url= '/~username/manager/';
    define('MODX_MANAGER_PATH', $modx_manager_path);
    define('MODX_MANAGER_URL', $modx_manager_url);
}
if (!defined('MODX_BASE_PATH')) {
    $modx_base_path= '/home/usernamel/public_html/';
    $modx_base_url= '/~username/';
    define('MODX_BASE_PATH', $modx_base_path);
    define('MODX_BASE_URL', $modx_base_url);
}
if(defined('PHP_SAPI') && (PHP_SAPI == "cli" || PHP_SAPI == "embed")) {
    $isSecureRequest = false;
} else {
    $isSecureRequest = ((isset ($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['SERVER_PORT'] == $https_port);
}
if (!defined('MODX_URL_SCHEME')) {
    $url_scheme=  $isSecureRequest ? 'https://' : 'http://';
    define('MODX_URL_SCHEME', $url_scheme);
}
if (!defined('MODX_HTTP_HOST')) {
    if(defined('PHP_SAPI') && (PHP_SAPI == "cli" || PHP_SAPI == "embed")) {
        $http_host='ourserver.com';
        define('MODX_HTTP_HOST', $http_host);
    } else {
        $http_host= $_SERVER['HTTP_HOST'];
        if ($_SERVER['SERVER_PORT'] != 80) {
            $http_host= str_replace(':' . $_SERVER['SERVER_PORT'], '', $http_host); // remove port from HTTP_HOST
        }
        $http_host .= ($_SERVER['SERVER_PORT'] == 80 || $isSecureRequest) ? '' : ':' . $_SERVER['SERVER_PORT'];
        define('MODX_HTTP_HOST', $http_host);
    }
}
if (!defined('MODX_SITE_URL')) {
    $site_url= $url_scheme . $http_host . MODX_BASE_URL;
    define('MODX_SITE_URL', $site_url);
}
if (!defined('MODX_ASSETS_PATH')) {
    $modx_assets_path= '/home/username/public_html/assets/';
    $modx_assets_url= '/~username/assets/';
    define('MODX_ASSETS_PATH', $modx_assets_path);
    define('MODX_ASSETS_URL', $modx_assets_url);
}
if (!defined('MODX_LOG_LEVEL_FATAL')) {
    define('MODX_LOG_LEVEL_FATAL', 0);
    define('MODX_LOG_LEVEL_ERROR', 1);
    define('MODX_LOG_LEVEL_WARN', 2);
    define('MODX_LOG_LEVEL_INFO', 3);
    define('MODX_LOG_LEVEL_DEBUG', 4);
}
if (!defined('MODX_CACHE_DISABLED')) {
    $modx_cache_disabled= false;
    define('MODX_CACHE_DISABLED', $modx_cache_disabled);
}
 

chrishirst

Well-Known Member
Staff member
ModX is a bit like WordPress in that it writes the base hostname to several places and they ALL have to be hanged to make it work correctly.

Joomla is easy, export the database, zip up the root directory, extract it on the new server, edit one file, import the database and you have an instant clone site on a new URI.

So what I would suggest is, rather than trying to edit every line of code where ~username is embedded, is to export the DB and uninstall ModX using Softaculous, then login to cPanel using site.tld:2083 and reinstall, that will allow you configure it correctly.
If you have added any data you 'should' be able to set the same database and table name prefix and import it back in.
 

drding

New Member
Yeah I had a feeling it might come down to redoing things. Luckily it's a small site so even if I can't get the database import to work, I can rebuild the whole thing in an hour or two.

I've briefly dabbled with Joomla, but that transfer process sounds amazing. Maybe I should check it out again :D

Thanks again for all your help!
 
I tried it out and I think I'm commenting out the wrong part of the script, I did clear out my cache folder just in case too.

Here's part of my config file with confidential parts removed and/or edited. Could you point out which part I should comment out? I really appreciate all the assistance so far, you've been a huge help.

Code:
if (!defined('MODX_CORE_PATH')) {
    $modx_core_path= '/home/username/public_html/core/';
    define('MODX_CORE_PATH', $modx_core_path);
}
if (!defined('MODX_PROCESSORS_PATH')) {
    $modx_processors_path= '/home/username/public_html/core/model/modx/processors/';
    define('MODX_PROCESSORS_PATH', $modx_processors_path);
}
if (!defined('MODX_CONNECTORS_PATH')) {
    $modx_connectors_path= '/home/username/public_html/connectors/';
    $modx_connectors_url= '/~username/connectors/';
    define('MODX_CONNECTORS_PATH', $modx_connectors_path);
    define('MODX_CONNECTORS_URL', $modx_connectors_url);
}
if (!defined('MODX_MANAGER_PATH')) {
    $modx_manager_path= '/home/username/public_html/manager/';
    $modx_manager_url= '/~username/manager/';
    define('MODX_MANAGER_PATH', $modx_manager_path);
    define('MODX_MANAGER_URL', $modx_manager_url);
}
if (!defined('MODX_BASE_PATH')) {
    $modx_base_path= '/home/usernamel/public_html/';
    $modx_base_url= '/~username/';
    define('MODX_BASE_PATH', $modx_base_path);
    define('MODX_BASE_URL', $modx_base_url);
}
if(defined('PHP_SAPI') && (PHP_SAPI == "cli" || PHP_SAPI == "embed")) {
    $isSecureRequest = false;
} else {
    $isSecureRequest = ((isset ($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['SERVER_PORT'] == $https_port);
}
if (!defined('MODX_URL_SCHEME')) {
    $url_scheme=  $isSecureRequest ? 'https://' : 'http://';
    define('MODX_URL_SCHEME', $url_scheme);
}
if (!defined('MODX_HTTP_HOST')) {
    if(defined('PHP_SAPI') && (PHP_SAPI == "cli" || PHP_SAPI == "embed")) {
        $http_host='ourserver.com';
        define('MODX_HTTP_HOST', $http_host);
    } else {
        $http_host= $_SERVER['HTTP_HOST'];
        if ($_SERVER['SERVER_PORT'] != 80) {
            $http_host= str_replace(':' . $_SERVER['SERVER_PORT'], '', $http_host); // remove port from HTTP_HOST
        }
        $http_host .= ($_SERVER['SERVER_PORT'] == 80 || $isSecureRequest) ? '' : ':' . $_SERVER['SERVER_PORT'];
        define('MODX_HTTP_HOST', $http_host);
    }
}
if (!defined('MODX_SITE_URL')) {
    $site_url= $url_scheme . $http_host . MODX_BASE_URL;
    define('MODX_SITE_URL', $site_url);
}
if (!defined('MODX_ASSETS_PATH')) {
    $modx_assets_path= '/home/username/public_html/assets/';
    $modx_assets_url= '/~username/assets/';
    define('MODX_ASSETS_PATH', $modx_assets_path);
    define('MODX_ASSETS_URL', $modx_assets_url);
}
if (!defined('MODX_LOG_LEVEL_FATAL')) {
    define('MODX_LOG_LEVEL_FATAL', 0);
    define('MODX_LOG_LEVEL_ERROR', 1);
    define('MODX_LOG_LEVEL_WARN', 2);
    define('MODX_LOG_LEVEL_INFO', 3);
    define('MODX_LOG_LEVEL_DEBUG', 4);
}
if (!defined('MODX_CACHE_DISABLED')) {
    $modx_cache_disabled= false;
    define('MODX_CACHE_DISABLED', $modx_cache_disabled);
}
Thanks for your valuable suggestion. This is very helpful to us.
 
Top