Last modified: 2013-05-15 23:18:11 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T27882, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 25882 - Canonical URL on all content pages
Canonical URL on all content pages
Status: NEW
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
1.16.x
All All
: Normal enhancement with 1 vote (vote)
: ---
Assigned To: Nobody - You can work on this!
:
: 26116 (view as bug list)
Depends on: 28602
Blocks:
  Show dependency treegraph
 
Reported: 2010-11-10 23:12 UTC by pioneeroverc
Modified: 2013-05-15 23:18 UTC (History)
5 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description pioneeroverc 2010-11-10 23:12:03 UTC
Right now, the canonical URL meta tag shows only on redirect(ed) pages.  Since sometimes (i.e. using file cache) URLs are not redirected, it would be nice to have the canonical URL meta tag on all (content) pages, which wouldn't hurt anyway.
Comment 1 Ilmari Karonen 2010-11-22 20:28:25 UTC
A wiki I help to run had need for this, so I wrote a quick and dirty hook to add rel=canonical links to all normal page views:

 $wgHooks['ArticleViewHeader'][] = 'addCanonicalLinks';
 function addCanonicalLinks ( &$article ) {
         global $wgRequest, $wgOut;
         if ( $article->getOldID() || $wgRequest->getVal( 'redirect' ) == 'no' ) return true;
         $tags = ( $wgOut->mLinktags ? $wgOut->mLinktags : array() );
         foreach ( $tags as $tag ) {
                 if ( $tag['rel'] === 'canonical' ) return true;
         }
         $wgOut->addLink( array( 'rel' => 'canonical',
         			'href' => $article->getTitle()->getFullURL() ) );
         return true;
 }

Ideally, of course, we should have some way for extensions and core components to indicate which URL parameters actually affect the content of the page, so that correct canonical links could be automatically constructed for all pages and actions.  But this simple workaround should handle 99% of all cases.
Comment 2 Alexandre Emsenhuber [IAlex] 2010-11-25 10:08:52 UTC
*** Bug 26116 has been marked as a duplicate of this bug. ***
Comment 3 pioneeroverc 2011-02-08 22:31:27 UTC
Any progress on this?  Someone willing to implement the hack above (or write another one) into MediaWiki's main code?
Comment 4 Bawolff (Brian Wolff) 2011-02-08 22:35:17 UTC
I don't understand the usecase. What do you mean by

>Since sometimes (i.e. using file cache) URLs are not redirected

(Since we don't use http redirects for redirects, url's are never redirected if you're saying what i think you are).
Comment 5 pioneeroverc 2011-02-08 23:30:45 UTC
(In reply to comment #4)
> I don't understand the usecase. What do you mean by
> 
> >Since sometimes (i.e. using file cache) URLs are not redirected
> 
> (Since we don't use http redirects for redirects, url's are never redirected if
> you're saying what i think you are).

Say I go to http://mywiki.com/my%20page.  If I'm logged in, I'm redirected to http://mywiki.com/My_page.  However, if I'm not logged in, I have file cache enabled and I visit that URL, I'm not redirected, though the page shows the content of what technically is My_page.  I have a non-standard configuration (using nginx and short URLs like mywiki.com/Page) and I don't know if it's the same using Apache and/or short URLs like mywiki.com/wiki/Page, but enabling canonical URLs on all pages would definitely get rid of the SEO and indexing-related problems, possibly even in other cases, using index.php?title=Page instead of /Page and surely others I can't think of right now.
Comment 6 Mark A. Hershberger 2011-02-10 02:53:18 UTC
Bawolff, do you understand this now? Feel like taking a stab at it?
Comment 7 Bawolff (Brian Wolff) 2011-02-10 03:14:37 UTC
I understand the request, but I don't know enough about how search engines use canonical links, to know if having a canonical link pointing to the current page will have an adverse affect. One would assume it wouldn't, but I don't really know.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links