CodeIgniter Forums
Routing {locale} : Duplicate Content [SOLVED in next release] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Routing {locale} : Duplicate Content [SOLVED in next release] (/showthread.php?tid=82316)



Routing {locale} : Duplicate Content [SOLVED in next release] - InstantT - 06-29-2022

Hi all,
When we use the "{locale}" tag in a route, it can generate Duplicate Content, even when using the $supportedLocales variable

For example if I use :
PHP Code:
public $supportedLocales = ['en''fr']; 


When I go to a url of type
- mywebsite.com/en/page.html = code 200 ("en" version)
- mywebsite.com/en/page.html = code 200 ("fr" version or "en" version if "fr" does not exist)
- mywebsite.com/lorem/page.html = code 200 ("en" version)
- mywebsite.com/codeignitertest/page.html = code 200 ("en" version) etc.

Do we have to check in our Controller that the language exists?
And if yes, how to get the information from the $supportedLocales variable?

Otherwise, wouldn't it be interesting in the next version, to put an option to avoid this duplicate content

For example, if {locale} does not correspond to any language present in $supportedLocales, then, we return a 404 error

Regards

Ps : The variable "$supportedLocales" is defined as "@var string[]"

What is the difference with "@var array"? (it's just for my personal culture Smile )


RE: Routing {locale} : Duplicate Content - kenjis - 06-29-2022

(06-29-2022, 10:09 AM)InstantT Wrote: Do we have to check in our Controller that the language exists?
And if yes, how to get the information from the $supportedLocales variable?

Otherwise, wouldn't it be interesting in the next version, to put an option to avoid this duplicate content

For example, if {locale} does not correspond to any language present in $supportedLocales, then, we return a 404 error

Yes, you need to check now.

And v4.3 will have the option.
See https://github.com/codeigniter4/CodeIgniter4/pull/6073

(06-29-2022, 10:09 AM)InstantT Wrote: Ps : The variable "$supportedLocales" is defined as "@var string[]"

What is the difference with "@var array"? (it's just for my personal culture Smile )

string[] means array of string items.
Controller[] means array of Controller objects.


RE: Routing {locale} : Duplicate Content - InstantT - 06-30-2022

Thank you @kenjis

So I will wait for the release of this new version Smile

I'm still not sure I understand the difference between "string[]" and "array" (not Controller)


RE: Routing {locale} : Duplicate Content [SOLVED in next release] - iRedds - 06-30-2022

string[] means that the array contains only strings as values. ['a', 'b', 'text', ]
array - means that it is an array with any content. ['a', 1, new stdClass, null, false]

This gives an idea of what the array contains, and in the case of the IDE, you can get hints.


RE: Routing {locale} : Duplicate Content [SOLVED in next release] - InstantT - 06-30-2022

@iRedds : Thank you very much for this clarification.

I understand Smile