Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

SEO trick (for developers)

SS ✭✭
edited March 2011 in Vanilla 2.0 - 2.8
For example, news. Just example, no explanations

Example:

// class.newsconttroller.php // file

// public function Index($Code) {
if (is_numeric($Code)) {
$this->View($Code);
}
// elseif(... other check for news category url code, etc.
}

...
// public function View() { // method
...
// trick
$NewsModel = Gdn_NewsModel();
$Story = $NewsModel->GetID($NewsID);
...
$NewsStoryURL = 'news/'.$Story->NewsID.'/'.Gdn_Format::Url($News->Title); // or you can use Clean() method
$CanonicalUrl = $this->CanonicalUrl(Url($NewsStoryURL, True));
if ($NewsStoryURL != $this->SelfUrl) Redirect($CanonicalUrl, 301);
...

Comments

  • aeryaery Gtricks Forum in 2.2 :) ✭✭✭
    @S , an explanation will be appreciated :)

    There was an error rendering this rich post.

  • SS ✭✭
    I'll try to find free time...
  • I'm studying Php..And see i dono what technique used here ,can you please explain..
    www.oreeka.co.uk
  • @S Thanks!
    We can provide any original contents to bind url in this way within Garden framework, right?
    I'll try it out later.
  • We can provide any original contents to bind url in this way within Garden framework, right
    @yu_tang : I would love to learn what you mean with that. Do you have an example?

    There was an error rendering this rich post.

  • LincLinc Detroit Admin
    He's forcing the page to 301 redirect to the canonical URL rather than allowing it to remain at a non-canonical URL. By default, Vanilla doesn't care what the title part of the URL is. @S's example forces it to fix itself.
  • Oops, I have misunderstood.
    Thanks @Lincoln!
    I posted, sleeped and woke up. Now I'm back in here and read this before to start coding.
    It's my lucky day.
Sign In or Register to comment.