I know that my post is about 2.3.4 BS GOLD, not Phoenix, but the new people at oscommerce.com suggested that their forum is no longer the place for support of previous versions... so you are my only hope.
I'm trying to add a canonical link in mysite.com/myosc/index.php that would point to mysite.com/myosc/
I'm trying to prevent Google from seeing those as 2 different pages. I've already removed index.php from my internal links, I just need to add a canonical link or redirect to make it clear to Google.
If I'm not mistaken, index.php is used for more than just the front page of the store? Like it's used to list products in categories and manufacturers, etc? (I have Ultimate SEO installed so that part may be obfuscated in the URLs, thus my hesitation)
What's the best way to either add a canonical link to my index.php only when appropriate?
Or am I better off having a redirect in my htaccess? If so, how should it make sure only to redirect when it's the actual front page of the store, and not a category/manufacturer/etc?
Thank you kindly.
p.s. Yes, ideally I'd upgrade to Phoenix and use the new Header Tags Seo. Unfortunately it's not an option right this moment, but I'm looking into it.
Adding a canonical link, or redirect, to index.php
-
- Lead Developer
- Posts: 2656
- Joined: Tue Nov 05, 2019 6:02 pm
- Has thanked: 4 times
- Been thanked: 182 times
Re: Adding a canonical link, or redirect, to index.php
As best I can see, this version of the header tag module should work: https://github.com/CE-PhoenixCart/Phoen ... onical.php
Re: Adding a canonical link, or redirect, to index.php
Unfortunately that version breaks my site.ecartz wrote: ↑Thu May 13, 2021 3:16 am As best I can see, this version of the header tag module should work: https://github.com/CE-PhoenixCart/Phoen ... onical.php
Just the same, by comparing my version with the Phoenix version, I was able to feel confident enough to modify my ht_canonical for my purpose.
My execute function looked like this:
Code: Select all
function execute() {
global $PHP_SELF, $HTTP_GET_VARS, $cPath, $oscTemplate;
if (basename($PHP_SELF) == FILENAME_PRODUCT_INFO) {
$oscTemplate->addBlock('<link rel="canonical" href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . (int)$HTTP_GET_VARS['products_id'], 'NONSSL', false) . '" />' . "\n", $this->group);
} elseif (basename($PHP_SELF) == FILENAME_DEFAULT) {
if (isset($cPath) && tep_not_null($cPath)) {
$oscTemplate->addBlock('<link rel="canonical" href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $cPath, 'NONSSL', false) . '" />' . "\n", $this->group);
} elseif (isset($HTTP_GET_VARS['manufacturers_id']) && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
$oscTemplate->addBlock('<link rel="canonical" href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . (int)$HTTP_GET_VARS['manufacturers_id'], 'NONSSL', false) . '" />' . "\n", $this->group);
}
}
}
Code: Select all
function execute() {
global $PHP_SELF, $HTTP_GET_VARS, $cPath, $oscTemplate;
if (basename($PHP_SELF) == FILENAME_PRODUCT_INFO) {
$oscTemplate->addBlock('<link rel="canonical" href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . (int)$HTTP_GET_VARS['products_id'], 'NONSSL', false) . '" />' . "\n", $this->group);
} elseif (basename($PHP_SELF) == FILENAME_DEFAULT) {
if (isset($cPath) && tep_not_null($cPath)) {
$oscTemplate->addBlock('<link rel="canonical" href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $cPath, 'NONSSL', false) . '" />' . "\n", $this->group);
} elseif (isset($HTTP_GET_VARS['manufacturers_id']) && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
$oscTemplate->addBlock('<link rel="canonical" href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . (int)$HTTP_GET_VARS['manufacturers_id'], 'NONSSL', false) . '" />' . "\n", $this->group);
} elseif ($cPath == '') {
$oscTemplate->addBlock('<link rel="canonical" href="' . tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false) . '" />' . "\n", $this->group);
}
}
}
Re: Adding a canonical link, or redirect, to index.php
You can simply edit your index page and add below line
or
You can simply edit your .htaccess with below script as i did it.
Replace /myosc/ with your URL path..
This code will redirect any request to index.php to the root URL of your site using a 301 redirect.
This is beneficial for SEO Ranking search engines
Once done you can verify your URL manually by using browser developer tools to inspect network requests and redirects or use an online tool
Code: Select all
<link rel="canonical" href="https://www.mysite.com/myosc/" />
You can simply edit your .htaccess with below script as i did it.
Code: Select all
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /myosc/index\.php [NC]
RewriteRule ^ /myosc/ [R=301,L]
This code will redirect any request to index.php to the root URL of your site using a 301 redirect.
This is beneficial for SEO Ranking search engines
Once done you can verify your URL manually by using browser developer tools to inspect network requests and redirects or use an online tool