I have just recently noticed that the SEO URL's seem to be causing invalid markup errors through the W3C Validator.
http://validator.w3.org/
The issue seems relative to the SEO URL's combined with the sort/limit parameters and the way that unescaped ampersands are included in the URL's.
With SEO URL's disabled, every page will pass validation (with correctly encoded & for ampersands) every time no matter which combination of sort and limit parameters are selected. However, as soon as SEO URL's are enabled the errors show up through the W3C Validator.
Although I am not running the latest version of OpenCart, I have checked this on the latest release and the issue is still present.
I am really not sure how to fix this but if any insight could be provided, it would be appreciated greatly.
Edit: This solution is not optimum. Please see this post below for the correct solution: http://forum.opencart.com/viewtopic.php ... 61#p413635
In the file: catalog/controller/common/seo_url.php
I changed:
if ($data) {
foreach ($data as $key => $value) {
$query .= '&' . $key . '=' . $value;
}
if ($query) {
$query = '?' . trim($query, '&');
}
}
To:
if ($data) {
foreach ($data as $key => $value) {
$query .= '&' . $key . '=' . $value;
}
if ($query) {
$query = '?' . trim($query, '&');
}
}
Now every URL regardless of the sort & limit parameters will pass W3C validation. From this it would seem that this section of code was responsible for the unescaped ampersands in the SEO URL's.
I have confirmed that W3C validation now passes both with and without SEO URL's enabled.
Note: I initially tried using the entity name (&) in the code above, but this resulted in the pagination links breaking so tried the entity number (&) and everything seems to be working perfectly.
In the file: catalog/controller/common/seo_url.php
I changed:
if ($data) {
foreach ($data as $key => $value) {
$query .= '&' . $key . '=' . $value;
}
if ($query) {
$query = '?' . trim($query, '&');
}
}
To:
if ($data) {
foreach ($data as $key => $value) {
$query .= '&' . $key . '=' . $value;
}
if ($query) {
$query = '?' . trim($query, '&');
}
}
Now every URL regardless of the sort & limit parameters will pass W3C validation. From this it would seem that this section of code was responsible for the unescaped ampersands in the SEO URL's.
I have confirmed that W3C validation now passes both with and without SEO URL's enabled.
Note: I initially tried using the entity name (&) in the code above, but this resulted in the pagination links breaking so tried the entity number (&) and everything seems to be working perfectly.
Last edited by storm-cloud on Sat Jun 15, 2013 12:34 pm, edited 2 times in total.
My apologies for digging up this thread but I recently discovered that the modification above does not play nice with another modification which displays canonical meta tags on category pages.
The issue is that this modification seems to be stripping the page number from the canonical meta tag when it contains a "3" or "8" as these characters are stated within the trim.
To clarify, when viewing page 3 of a category page (?page=3), the modification that I posted above will also trim the 3 from the page parameter for the canonical meta tag, as 3 is one of the characters listed in the the trim. This will also apply to page 8 or any other pages which include the character 3 or 8.
Also as mentioned previously, using & instead of & results in the characters "p" and "a" also being trimmed (?page= becomes ?ge=).
I can't think of any other way to fix this small bug.
Just to recap the issue. When enabling SEO URL's, instead of & being displayed in the URL for sort and limit parameters, an unescaped & is present instead.
I was wondering if there was perhaps a more correct way of resolving this issue?
The issue is that this modification seems to be stripping the page number from the canonical meta tag when it contains a "3" or "8" as these characters are stated within the trim.
Code: Select all
$query = '?' . trim($query, '&');
Also as mentioned previously, using & instead of & results in the characters "p" and "a" also being trimmed (?page= becomes ?ge=).
Code: Select all
$query = '?' . trim($query, '&');
Just to recap the issue. When enabling SEO URL's, instead of & being displayed in the URL for sort and limit parameters, an unescaped & is present instead.
I was wondering if there was perhaps a more correct way of resolving this issue?
Ok, I have a better solution.
In catalog/controller/common/seo_url.php
Change:
To:
And Change:
To:
In catalog/controller/common/seo_url.php
Change:
Code: Select all
$query .= '&' . $key . '=' . $value;
Code: Select all
$query .= '&' . $key . '=' . $value;
Code: Select all
$query = '?' . trim($query, '&');
Code: Select all
$query = '?' . substr($query, 5);
Who is online
Users browsing this forum: No registered users and 3 guests