by marky9378 » Sat Jul 05, 2008 4:08 am
I have a forum on this website which has a .htaccess using php to automatically convert into friendly uls.
Could someone tell me how i can use this on the directory above script.
PHP
<?php
/**
* Prepares an URL for URL Rewriting
*
* @param string $type
* @param int $id
* @param string $name
* @return string
* @author Dale Smith <info@wwwthreads.com>
*/
function makeurl($type, $id, $name)
{
$url = strtr($name,'ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ/','AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn-');
$url=preg_replace('/ /', '-', $url);
$url=trim(preg_replace('/[^a-z|A-Z|0-9|-]/', '', strtolower($url)), '-');
$url=preg_replace('/\-+/', '-', $url);
$url = urlencode($type . $id .'-'. $url .'.html');
return $url;
}
function replace_for_mod_rewrite(&$s) {
$urlin = array(
"/\"([^.]*).php\?([a-z0-9_]*)=([a-zA-Z0-9_.]*)((&)|&)+([a-z0-9_]*)=([a-zA-Z0-9_.]*)((&)|&)+([a-z0-9_]*)=([a-zA-Z0-9_.]*)\"/"
, "/\"([^.]*).php\?([a-z0-9_]*)=([a-zA-Z0-9_.]*)((&)|&)+([a-z0-9_]*)=([a-zA-Z0-9_.]*)\"/"
, "/\"([^.]*).php\?([a-z0-9_]*)=([a-zA-Z0-9_.]*)\"/"
, "/\"([^.]*).php\"/"
);
$urlout = array(
"\"\\1-\\2-\\3-\\6-\\7-\\10-\\11.html\""
, "\"\\1-\\2-\\3-\\6-\\7.html\""
, "\"\\1-\\2-\\3.html\""
, "\"\\1.html\""
);
$s = preg_replace($urlin, $urlout, $s);
return $s;
}
function replace_for_mod_rewrite1(&$s) { //debug!
$urlin = array(
"/([^.]*).php\?([a-z0-9_]*)=([a-zA-Z0-9_.]*)[(&)|&]+([a-z0-9_]*)=([a-zA-Z0-9_.]*)[(&)|&]+([a-z0-9_]*)=([a-zA-Z0-9_.]*)([^'])/"
, "/([^.]*).php\?([a-z0-9_]*)=([a-zA-Z0-9_.]*)[(&)|&]+([a-z0-9_]*)=([a-zA-Z0-9_.]*)([^'])/"
, "/([^.]*).php\?([a-z0-9_]*)=([a-zA-Z0-9_.]*)([^'])/"
, "/([^.]*).php([^'])/"
);
$urlout = array(
"\\1-\\2-\\3-\\4-\\5-\\6-\\7.html\\8"
, "\\1-\\2-\\3-\\4-\\5.html\\6"
, "\\1-\\2-\\3.html\\4"
, "\\1.html\\2"
);
$s = preg_replace($urlin, $urlout, $s);
return $s;
}
/*
function replace_for_mod_rewrite2(&$s) { //slow?
$urlin = array(
"/([^.]*).php\?([a-z0-9_]*)=([a-zA-Z0-9_.]*)[(&)|&]+([a-z0-9_]*)=([a-zA-Z0-9_.]*)[(&)|&]+([a-z0-9_]*)=([a-zA-Z0-9_.]*)/"
, "/([^.]*).php\?([a-z0-9_]*)=([a-zA-Z0-9_.]*)[(&)|&]+([a-z0-9_]*)=([a-zA-Z0-9_.]*)/"
, "/([^.]*).php\?([a-z0-9_]*)=([a-zA-Z0-9_.]*)/"
, "/([^.]*).php/"
);
$urlout = array(
"\\1-\\2-\\3-\\4-\\5-\\6-\\7.html"
, "\\1-\\2-\\3-\\4-\\5.html"
, "\\1-\\2-\\3.html"
, "\\1.html"
);
$s = preg_replace($urlin, $urlout, $s);
return $s;
}
*/
function replace_for_mod_rewrite2(&$s) { //slow?
$urlin = array(
"/([^.]*).php\?([a-z0-9_]*)=([a-zA-Z0-9_.]*)((&)|&)+([a-z0-9_]*)=([a-zA-Z0-9_.]*)((&)|&)+([a-z0-9_]*)=([a-zA-Z0-9_.]*)/"
, "/([^.]*).php\?([a-z0-9_]*)=([a-zA-Z0-9_.]*)((&)|&)+([a-z0-9_]*)=([a-zA-Z0-9_.]*)/"
, "/([^.]*).php\?([a-z0-9_]*)=([a-zA-Z0-9_.]*)/"
, "/([^.]*).php/"
);
$urlout = array(
"\\1-\\2-\\3-\\6-\\7-\\10-\\11.html"
, "\\1-\\2-\\3-\\6-\\7.html"
, "\\1-\\2-\\3.html"
, "\\1.html"
);
$s = preg_replace($urlin, $urlout, $s);
return $s;
}
?>
.HTACCESS
RewriteEngine on
RewriteRule ^f([0-9]+)(.*).html$ view_forum.php?id=$1 [L]
RewriteRule ^t([0-9]+)(.*).html$ view_topic.php?id=$1 [L]
RewriteRule ^p([0-9]+)(.*).html$ view_topic.php?pid=$1 [L]
RewriteRule ^l([0-9]+)(.*).html$ view_poll.php?pid=$1 [L]
####### extra
RewriteRule ^(.*)spell.html$ $1spell.html [L]
RewriteRule ^(.*)-(.*)-(.*)-(.*)-(.*)-(.*)-(.*).html$ $1.php?$2=$3&$4=$5&$6=$7 [L]
RewriteRule ^(.*)-(.*)-(.*)-(.*)-(.*).html$ $1.php?$2=$3&$4=$5 [L]
RewriteRule ^(.*)-(.*)-(.*).html$ $1.php?$2=$3 [L]
RewriteRule ^(.*).html$ $1.php [L]
#######
RewriteRule ^(.*).rss$ extern.php?action=$1&type=rss [L]
RewriteRule ^blabla.html$ index.php [L]
Please Help