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
RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/admin/([a-zA-Z0-9\&\%\?\_\.\-\=]+) modules/myalbum/admin/$3 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/admin/([a-zA-Z0-9\&\%\?\_\.\-\=]+) modules/myalbum/admin/$2 [L,NC,QSA] RewriteRule ^album/admin/([a-zA-Z0-9\&\%\_\-\=\?\.]+) modules/myalbum/admin/$1 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/comment_([a-zA-Z0-9\&\%\?\_\.\-\=]+) modules/myalbum/comment_$3 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/comment_([a-zA-Z0-9\&\%\?\_\.\-\=]+) modules/myalbum/comment_$2 [L,NC,QSA] RewriteRule ^album/comment_([a-zA-Z0-9\&\%\_\-\=\?\.]+) modules/myalbum/comment_$1 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/images/([a-zA-Z0-9\ \%\_\-]+)/(.*) modules/myalbum/images/$3/$4 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/images/(.*) modules/myalbum/images/$3 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/images/([a-zA-Z0-9\ \%\_\-]+)/(.*) modules/myalbum/images/$2/$3 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/images/(.*) modules/myalbum/images/$2 [L,NC,QSA] RewriteRule ^album/images/([a-zA-Z0-9\ \%\_\-]+)/(.*) modules/myalbum/images/$1/$2 [L,NC,QSA] RewriteRule ^album/images/(.*) modules/myalbum/images/$1 [L,NC,QSA] RewriteRule ^albumimages/([a-zA-Z0-9\ \%\_\-]+)/(.*) modules/myalbum/images/$1/$2 [L,NC,QSA] RewriteRule ^albumimages/(.*) modules/myalbum/images/$1 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/submit.php modules/myalbum/submit.php [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/submit.php modules/myalbum/submit.php [L,NC,QSA] RewriteRule ^album/submit.php modules/myalbum/submit.php [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/index.php modules/myalbum/index.php [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/viewcat.php?([a-zA-Z0-9\=\&\_\-]+)$ modules/myalbum/viewcat.php?$3 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/editphoto.php?([a-zA-Z0-9\=\&\_\-]+)$ modules/myalbum/editphoto.php?$3 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/ratephoto.php?([a-zA-Z0-9\=\&\_\-]+)$ modules/myalbum/ratephoto.php?$3 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/index.php modules/myalbum/index.php [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/viewcat.php?([a-zA-Z0-9\=\&\_\-]+)$ modules/myalbum/viewcat.php?$2 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/editphoto.php?([a-zA-Z0-9\=\&\_\-]+)$ modules/myalbum/editphoto.php?$2 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/ratephoto.php?([a-zA-Z0-9\=\&\_\-]+)$ modules/myalbum/ratephoto.php?$2 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/addto/(.*) modules/myalbum/addto/$3 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/addto/(.*) modules/myalbum/addto/$2 [L,NC,QSA] RewriteRule ^album/addto/(.*) modules/myalbum/addto/$1 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/([0-9]+),([0-9]+)$ modules/myalbum/photo.php?ads_cat=$1&ads_title=$2&lid=$3&cid=$4 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/$ modules/myalbum/photo.php?ads_cat=$1&ads_title=$2 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)$ modules/myalbum/photo.php?ads_cat=$1&ads_title=$2 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/index.php modules/myalbum/index.php [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/viewcat.php?([a-zA-Z0-9\=\&\_\-]+)$ modules/myalbum/viewcat.php?$3 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/([a-zA-Z0-9\ \%\_\-]+)/index.php modules/myalbum/index.php [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/([0-9]+),([0-9]+),([0-9]+),([0-9]+),([0-9]+),([a-zA-Z0-9]+)$ modules/myalbum/viewcat.php?ads_cat=$1&cid=$2&uid=$3&num=$4&pos=$5&view=$6&orderby=$7 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)/$ modules/myalbum/viewcat.php?ads_cat=$1 [L,NC,QSA] RewriteRule ^album/([a-zA-Z0-9\ \%\_\-]+)$ modules/myalbum/viewcat.php?ads_cat=$1 [L,NC,QSA] RewriteRule ^album/([0-9]+),([0-9]+) modules/myalbum/index.php?num=$1&pos=$2 [L,NC,QSA] RewriteRule ^album/editphoto.php?([a-zA-Z0-9\=\&\_\-]+)$ modules/myalbum/editphoto.php?$1 [L,NC,QSA] RewriteRule ^album/ modules/myalbum/index.php [L,NC,QSA] RewriteRule ^album modules/myalbum/index.php [L,NC,QSA]
[edit]
Change to the code
[edit]
index.php
Insert at line 8
if (strpos(' '.$_SERVER['REQUEST_URI'],'modules/')>0){
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: ".XOOPS_URL."/album/");
}
[edit]
photo.php
insert after include('../../mainfile.php');
$ads_title = empty( $_GET['ads_title'] ) ? '' : ( sef($_GET['ads_title'],'_') ) ;
$ads_cat = empty( $_GET['ads_cat'] ) ? '' : ( sef($_GET['ads_cat'],'_') ) ;
if ($lid==0&&$ads_cat!=''&&$ads_title!=''){
$sql = "SELECT a.lid, a.cid FROM ".$xoopsDB->prefix('myalbum_photos')." a INNER JOIN ".$xoopsDB->prefix('myalbum_cat')." b on a.cid = b.cid WHERE a.title LIKE '$ads_title' AND b.title LIKE '$ads_cat'";
$ret = $xoopsDB->query($sql);
$rt = $xoopsDB->fetchArray($ret);
$lid = $rt['lid'];
$cid = $rt['cid'];
}
if ($ads_cat==''&&$ads_title==''){
$sql = "SELECT a.title, b.title as cat_title, a.lid, a.cid FROM ".$xoopsDB->prefix('myalbum_photos')." a INNER JOIN ".$xoopsDB->prefix('myalbum_cat')." b on a.cid = b.cid WHERE a.lid=$lid";
$ret = $xoopsDB->query($sql);
$rt = $xoopsDB->fetchArray($ret);
header( "HTTP/1.1 301 Moved albumly" );
header( "Location: ".XOOPS_URL."/album/".sef($rt['cat_title'])."/".sef($rt['title'])."/".$rt['lid'].",".$rt['cid']);
}
$query_rsTitle = "SELECT ".$xoopsDB->prefix('myalbum_photos').".comments ,".$xoopsDB->prefix('myalbum_photos').".title as phtTitle, ".$xoopsDB->prefix('myalbum_cat').".title as CatTitle FROM ".$xoopsDB->prefix('myalbum_photos')." inner join ".$xoopsDB->prefix('myalbum_cat')." on ".$xoopsDB->prefix('myalbum_cat').".cid = ".$xoopsDB->prefix('myalbum_photos').".cid where ".$xoopsDB->prefix('myalbum_photos').".lid = $lid";
$rsTitle = $xoopsDB->query($query_rsTitle);
$row_rsTitle = $xoopsDB->fetchArray($rsTitle);
$totalRows_rsTitle = mysql_num_rows($rsTitle);
if ($totalRows_rsTitle==0){
header( "HTTP/1.1 301 Moved albumly" );
header( "Location: http://".$_SERVER['HTTP_HOST']."/modules/myalbum/");
echo "301 - Moved or Deleted albumly - redirecting to <a href='http://".$_SERVER['HTTP_HOST']."/modules/myalbum/'>http://".$_SERVER['HTTP_HOST']."/modules/myalbum/</a>";
exit();
}
[edit]
viewcat.php
Insert from line 10:
$ads_cat = empty( $_GET['ads_cat'] ) ? '' : ( sef($_GET['ads_cat'],'_') ) ;
if ($ads_cat!=''&&$cid==0){
$sql = "SELECT b.title, b.cid FROM ".$xoopsDB->prefix('myalbum_cat')." b WHERE b.title LIKE '$ads_cat'";
$ret = $xoopsDB->query($sql);
$rt = $xoopsDB->fetchArray($ret);
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: ".XOOPS_URL."/album/".sef($rt['title'])."/".$rt['cid'].",$uid,$num,$pos,$view,$orderby");
}
if ($ads_cat==''){
$sql = "SELECT b.title, b.cid FROM ".$xoopsDB->prefix('myalbum_cat')." b WHERE b.cid=$cid";
$ret = $xoopsDB->query($sql);
$rt = $xoopsDB->fetchArray($ret);
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: ".XOOPS_URL."/album/".sef($rt['title'])."/".$cid.",$uid,$num,$pos,$view,$orderby");
}
if ($cid!=0){
$query_rsTitle = "SELECT count(*) as rec_count FROM ` ".$xoopsDB->prefix('myalbum_photos')."` WHERE ` ".$xoopsDB->prefix('myalbum_photos')."`.cid = $cid";
$rsTitle = $xoopsDB->query($query_rsTitle);
$row_rsTitle = $xoopsDB->fetchArray($rsTitle);
$totalRows_rsTitle = mysql_num_rows($rsTitle);
if ($row_rsTitle['rec_count']==0) {
header( "HTTP/1.1 302 Moved Temporarily" );
header( "Location: ".XOOPS_URL."/modules/myalbum/");
}
}

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





