Reputation: 11
I have built a new Opencart shop in a sub-directory of an old root domain : ie. http://www.old-domain.com/opencart Now I have a new domain name which now points ok to the sub-directory: ie. http://www.new-domain.com (I have updated both config.php files correctly) However, clicking on any internal link shows the old-domain url in the address bar.
So I need guidance in replacing (rewriting) the old name with the new one - whilst still retaining the correct paths etc. I have done a fair amount of research, and tried this and that in my htaccess without success. Thank you.
Upvotes: 1
Views: 321
Reputation: 3616
I believe this is what you need in your .htaccess so visitors to the old domain will be redirected to the new one. The R=301 assumes you've permanently moved to the new domain.:
RewriteCond %{HTTP_HOST} ^olddomain.com$
RewriteRule ^opencart/(.*)$ http://newdomain.com/$1 [R=301,L]
To make sure that all internal links are pointing to the new domain you need to
1 - Update your config.php files (which you have already done
2 - Replace all occurrences within content (information pages, product descriptions, banners. etc) of your old domain with the new one. phpMyAdmin has a handy search feature to find them all if you have access to it.
3 - There might still be references to your old domain hard-coded into your php & tpl files, but there shouldn't be - if there are you'll have to change these too (or better still fix them to use the constants defined in config.php)
Just a warning on #2 - if you are planning on changing these directly within phpMyAdmin don't update any serialised arrays unless you know what they are doing e.g.
a:1:{i:1;a:1:{i:0;s:28:"http://olddomain.com/opencart"}}
Upvotes: 0
Reputation: 16055
The problem is that OpenCart was installed on the old domain thus this URL address is set as constant (define) within its config files.
If You want to change it, go open these two files:
<OPENCART_ROOT>/config.php
<OPENCART_ROOT>/admin/config.php
and edit these defines:
// HTTP
define('HTTP_SERVER', 'http://olddomain.com/admin/');
define('HTTP_CATALOG', 'http://olddomain.com/');
define('HTTP_IMAGE', 'http://olddomain.com/image/');
// HTTPS
define('HTTPS_SERVER', 'http://olddomain.com/admin/');
define('HTTPS_CATALOG', 'http://olddomain.com/');
define('HTTPS_IMAGE', 'http://olddomain.com/image/');
to
// HTTP
define('HTTP_SERVER', 'http://newdomain.com/admin/');
define('HTTP_CATALOG', 'http://newdomain.com/');
define('HTTP_IMAGE', 'http://newdomain.com/image/');
// HTTPS
define('HTTPS_SERVER', 'http://newdomain.com/admin/');
define('HTTPS_CATALOG', 'http://newdomain.com/');
define('HTTPS_IMAGE', 'http://newdomain.com/image/');
(the config file within the root wouldn't have that /admin/
URLs part...)
This should solve Your problem.
Upvotes: 1