Contents |
[edit]
.htaccess & SEO
.htaccess file are used by apache to rewrite urls. This is very useful when doing an seo optimization. Some of you may have seen a couple of my sites where the modules are operating out side the /modules/ path this is done with a .htaccess file in the XOOPS_ROOT_PATH.
See .htaccess for more details
[edit]
.htaccess
This is the modification for SEO paths for News
RewriteRule ^news/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/comment_([a-zA-Z0-9\&\%\?\_\.\-\=]+) modules/news/comment_$3 [L,NC,QSA] RewriteRule ^news/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/images/(.*) modules/news/images/$2 [L,NC,QSA] RewriteRule ^news/([a-zA-Z0-9\ \%\_\-]+)/images/(.*) modules/news/images/$2 [L,NC,QSA] RewriteRule ^news/images/(.*) modules/news/images/$2 [L,NC,QSA] RewriteRule ^news/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/([0-9]+) modules/news/article.php?storycategory=$1&story_title=$2&storyid=$3 [L,NC,QSA] RewriteRule ^news/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/ modules/news/article.php?storycategory=$1&story_title=$2 [L,NC,QSA] RewriteRule ^news/([a-zA-Z0-9\ \%\_\-]+)/([0-9]+),([0-9]+) modules/news/index.php?storycategory=$1&topic_id=$2&start=$3 [L,NC,QSA] RewriteRule ^news/([a-zA-Z0-9\ \%\_\-]+)/ modules/news/index.php?storycategory=$1 [L,NC,QSA] RewriteRule ^news/([0-9]+),([0-9]+) modules/news/index.php?topic_id=$1&start=$2 [L,NC,QSA] RewriteRule ^news/ modules/news/index.php [L,NC,QSA] RewriteRule ^news modules/news/index.php [L,NC,QSA] RewriteRule ^news/article.php?storyid=([0-9]+) modules/news/article.php?storyid=$1 [L,NC,QSA]
[edit]
Changes to the code
[edit]
index.php
This is the change you have to make there is an IF statement at line 92, from line 91 to the end of this if statement this is the code you need.
$storytopic=0;
if(isset($_GET['storytopic'])||isset($_GET['storycategory'])) {
if (isset($_GET['storycategory'])){
$sql = "SELECT topic_id FROM ".$xoopsDB->prefix('topics')." WHERE topic_title Like '".$_GET['storycategory']."'";
$ret = $xoopsDB->query($sql);
$row = $xoopsDB->fetchArray($ret);
if ($row['topic_id']!=0){
$storytopic=$row['topic_id'];
}
} else {
$storytopic=intval($_GET['storytopic']);
$sql = "SELECT a.topic_title FROM ".$xoopsDB->prefix('topics')." a where a.topic_id = $storytopic";
$ret = $xoopsDB->query($sql);
$row = $xoopsDB->fetchArray($ret);
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: ".XOOPS_URL."/news/".sef($row['topic_title'])."/");
}
} else {
if(isset($_GET['topic_id'])) {
$storytopic=intval($_GET['topic_id']);
$sql = "SELECT a.topic_title FROM ".$xoopsDB->prefix('topics')." a where a.topic_id = $storytopic";
$ret = $xoopsDB->query($sql);
$row = $xoopsDB->fetchArray($ret);
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: ".XOOPS_URL."/news/".sef($row['topic_title'])."/");
}
}
[edit]
article.php
This is from line 128 to the end of the if statement below it, you will have to use this code.
$story_title = (isset($_GET['story_title'])) ? $_GET['story_title'] : '';
$storycategory = (isset($_GET['storycategory'])) ? $_GET['storycategory'] : '';
if (strlen($story_title)>0&&strlen($storycategory)>0){
$sql = "SELECT topic_id FROM ".$xoopsDB->prefix('topics')." WHERE topic_title Like '".$_GET['storycategory']."'";
$ret = $xoopsDB->query($sql);
$row = $xoopsDB->fetchArray($ret);
$sql = "SELECT storyid FROM ".$xoopsDB->prefix('stories')." WHERE title LIKE '$story_title' and topicid = ".$row['topic_id'];
$ret = $xoopsDB->queryF($sql);
$rt = $xoopsDB->fetchArray($ret);
$storyid = $rt['storyid'];
} else {
$storyid = (isset($_GET['storyid'])) ? intval($_GET['storyid']) : 0;
$sql = "SELECT a.topic_title, b.title FROM ".$xoopsDB->prefix('stories')." b INNER JOIN ".$xoopsDB->prefix('topics')." a on b.topicid = a.topic_id where b.storyid = $storyid";
$ret = $xoopsDB->query($sql);
$row = $xoopsDB->fetchArray($ret);
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: ".XOOPS_URL."/news/".sef($row['topic_title'])."/". sef($row['title'])."/");
}

![[Main Page]](/modules/mediawiki/images/mediawiki.png)





