CMS Made Simple Forums
https://forum.cmsmadesimple.org/

Changing news detail template and soft 404 errors
https://forum.cmsmadesimple.org/viewtopic.php?f=4&t=75121
Page 1 of 1

Author:  blast2007 [ Fri Jun 24, 2016 10:31 am ]
Post subject:  Changing news detail template and soft 404 errors

Hi all,
I have some pages calling news module with instruction like:
\$1:
{news category="General" summarytemplate="Responsive_News_Summary" detailtemplate="Responsive_News_Detail"}

As result of this, URLs of news detail page are something like:
\$1:
http://www.mysite.com/news/333/222/mynewstitle/d,Responsive_News_Detail.htm

I want to get rid of last URL part and have nice URLs like:
\$1:
http://www.mysite.com/news/333/222/mynewstitle.htm

To accomplish this, I have to remove "detailtemplate=..." instruction and create default template but what about SEO and soft 404 errors? Pages are already indexed but they are duplicated according to search engine because of same content.
One option is to edit .htaccess and create a 301 redirect but not all webmasters can access to it.

So here my CMSMS solution:
  1. Clone actual news detail template with a new name and make it default template.
  2. Create a new UDT named "moved301" with this code
    \$1:
    $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    $path = parse_url($url, PHP_URL_PATH);
    $pathComponents = explode("/", trim($path, "/"));
    $newurl = 'http://'.$_SERVER['HTTP_HOST']. '/'. $pathComponents[0] .'/'.$pathComponents[1] .'/'.$pathComponents[2] .'/'.$pathComponents[3] .'.htm';
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: $newurl");
  3. Edit old template and remove all content (but don't delete template) replacing with {moved301}
  4. Done!

Search engine trying to access detail template using old URL will be redirected with a 301 status code to new (short) URL.

Hope it helps
Regards
blast

Author:  Thomson [ Tue Aug 09, 2016 12:34 pm ]
Post subject:  Re: Changing news detail template and soft 404 errors

Thanks!!! O0

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/