hi,
i need rewrite www.myweb.com/index.php?id=1 (1 is random an image)
to www.myweb.com/id/1
thanks very much richardk for your answer.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^id/([0-9]+)/?$ /index.php?id=$1 [QSA,L]
richardk wrote:Try
- Code: Select all
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^id/([0-9]+)/?$ /index.php?id=$1 [QSA,L]
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^id/([^/]+)$ /index.php?id=$1 [QSA,L]
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9-_]*)/([1-9][0-9]*)-([a-zA-Z0-9-_]*).* modules.php?name=News&op=viewst&catseo=$1&sid=$2&titleseo=$3 [L]
RewriteRule ^([0-9]*)/([a-zA-Z0-9-_]*).html modules.php?name=News&op=viewcat&catid=$1&catseo=$2 [L]
RewriteRule ^([0-9]*)/([a-zA-Z0-9-_]*).html modules.php?name=News&op=viewcat&catid=$1&catseo=$2 [L]
$urlin = array(
'"(?<!/)modules.php\?name=News&op=viewst&catseo=([a-zA-Z0-9-_]*)&sid=([0-9]*)&titleseo=([a-zA-Z0-9-_]*)"',
'"(?<!/)modules.php\?name=News&op=viewcat&catid=([0-9]*)&catseo=([a-zA-Z0-9-_]*)"'
);
$urlout = array(
'\\1/\\2-\\3.html',
'\\1/\\2.html',);
<?php
if (!defined('TLNN_USE_SHORTLINKS')) {
die('Access Denied');
}
/*
* Configuration settings for ShortLinks
*/
$tlnn_sGTFileDir = 'ShortLinks'; // Name of Directory for GoogleTap Files. Should be located in root path with mainfile.php.
$tlnn_asGTFileExclude = array( // This array is only used while in debug mode if you don't want the admin to be bothered with the "untapped" notices below the footer
'Resend_Email', // This module should only be active for Administrators, so tapping it is unnecessary
'NukeSentinel', // One could tap this, but what is the point? Should probably only be available to admins anyways
'UserInfoAddons', // This module should only be active for Administrators, so tapping it is unnecessary
'block-Sentinel_Center.php', // Has no links, so why attempt to tap
'block-Sentinel_Scrolling.php', // Has no links, so why attempt to tap
'block-Sentinel_Side.php' // Has no links, so why attempt to tap, etc...
);
/*
* End of Configuration Options
*/
$tlnn_asGTFilePath = array(); // <-- Do NOT Touch!
$tlnn_asNoGTFile = array(); // <-- Do NOT Touch!
$tlnn_bDebugMode = (defined('NV_ADMIN') && isset($tlnn_bDebugShortLinks) && $tlnn_bDebugShortLinks) ? true : false; // <-- Do NOT Touch!
/**
* Function: tlnn_fPageTapStart
*
* Initiates the page tap for bufferring the output
*
* @return array of GT file paths if any
*/
function tlnn_fPageTapStart() {
global $prefix, $db, $admin, $tlnn_bDebugMode, $tlnn_sGTFileDir, $tlnn_bAutoTapLinks, $tlnn_asNoGTFile;
/*
* Modified by montego & xiketuan from http:// tanhlinh.com for ShortLinks
*/
$asGTFilePath = array();
$sGTFilePath = '';
if ($tlnn_bDebugMode) {
echo '[ShortLinks_Function] = Present In Header<br />';
}
if (isset($_REQUEST['name']) && $_REQUEST['name'] != '') {
$nextGenName = htmlentities(stripslashes($_REQUEST['name']));
if ($tlnn_bDebugMode) {
echo '[ShortLinks_ModuleName] = ' . $nextGenName . '<br />';
}
}
else
{ $nextGenName = "News";}
/*else {
$sql = 'SELECT main_module FROM ' . $prefix . '_main';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$mainmod_name = $row['main_module'];
$nextGenName = $mainmod_name;
if ($tlnn_bDebugMode) {
echo '[ShortLinks_ModuleName] = ' . $nextGenName . ' (Main Module)<br />';
}
}*/
/*
* GT-NExtGEn Files Path --- nextGenPath Variable
*/
$sGTFilePath = $tlnn_sGTFileDir . '/GT-' . $nextGenName . '.php';
if (@file_exists($sGTFilePath)) {
if ($tlnn_bDebugMode) {
echo '[ShortLinks_FilePath] = GT File :: ' . $sGTFilePath . ' :: Does Exist<br />';
}
ob_start();
array_push($asGTFilePath, $sGTFilePath);
define('TLNN_BUFFERED', TRUE);
} else {
if ($tlnn_bDebugMode) {
echo '[ShortLinks_FilePath] = GT File :: ' . $sGTFilePath . ' :: Does Not Exist!<br />';
}
$tlnn_asNoGTFile[] = $sGTFilePath;
}
/*
* Check for PageLevel tap file
*/
$sGTFilePath = $tlnn_sGTFileDir . '/GTZ-PageTap.php';
if (@file_exists($sGTFilePath)) {
if ($tlnn_bDebugMode) {
echo '[ShortLinks_FilePath] = GT File :: ' . $sGTFilePath . ' :: Does Exist<br />';
}
if (!defined('TLNN_BUFFERED')) { // Only buffer the output if it has not already been done
ob_start();
define('TLNN_BUFFERED', TRUE);
}
array_push($asGTFilePath, $sGTFilePath);
} else {
if ($tlnn_bDebugMode) {
echo '[ShortLinks_FilePath] = GT File :: ' . $sGTFilePath . ' :: Does Not Exist!<br />';
}
$tlnn_asNoGTFile[] = $sGTFilePath;
}
/*
* If none of the above produces a tap, need to check if debug is on AND if tlnn_bAutoTapLinks is TRUE
*/
if (!defined('TLNN_BUFFERED') && $tlnn_bDebugMode && isset($tlnn_bAutoTapLinks) && $tlnn_bAutoTapLinks) {
ob_start();
define('TLNN_BUFFERED', TRUE);
}
return $asGTFilePath;
}
/**
* Function: tlnn_fPageTapFinish
*
* Completes the page tap by taking the bufferred output and running through
* the various ShortLinks files (GT-<<module name>>.php).
*
* @return void does not return anything, but does output the final HTML
*/
function tlnn_fPageTapFinish() {
global $tlnn_bDebugMode, $tlnn_bAutoTapLinks, $tlnn_sGTFileDir, $tlnn_asNoGTFile, $tlnn_asGTFileExclude;
$asGTFilePathTmp = $GLOBALS['tlnn_asGTFilePath'];
if (defined('TLNN_BUFFERED')) {
$nextGenContent = ob_get_contents();
tlnn_fCleanLinks($nextGenContent);
ob_clean();
} else {
return;
}
/*
* GT-NExtGEn Footer Code --- nextGenFoot Variable
*/
if ($tlnn_bDebugMode) {
echo '<br />[ShortLinks_Function] = Present In Footer<br />';
}
/*
* GT-NExtGEn Block Code --- nextGenBlock Variable
* Modified by montego & xiketuan ShortLinks
* I moved this code out of the blocks, since I already have GTB tap file feature there. This, if enabled,
* will inspect ALL other non-tapped modules.php type links and either attempt to find a GT file to use,
* or report back any remaining un-tapped links to the admin if in debug mode.
*/
if (isset($tlnn_bAutoTapLinks) && $tlnn_bAutoTapLinks) {
if ($tlnn_bDebugMode) {
echo '[ShortLinks_Function] = Present in AutoTap Links Code<br />';
}
if (preg_match_all('(\b[name]{4}=[a-zA-Z0-9_-]+)', $nextGenContent, $asGotGenMatches)) { // Had links to modules
$sGTFilePath = '';
$asNoGTFile = array();
$asNewGotGenMatches = array_unique($asGotGenMatches[0]);
foreach($asNewGotGenMatches as $newGenMatch) {
$expGenMatch = explode('=', $newGenMatch);
$sGTFilePath = $tlnn_sGTFileDir . '/GT-' . $expGenMatch[1] . '.php';
if ($tlnn_bDebugMode) {
echo '[ShortLinks_TapLinks] = Found Links For Module: ' . $expGenMatch[1] . '<br />';
}
if (file_exists($sGTFilePath)) {
array_push($asGTFilePathTmp, $sGTFilePath);
} else {
$tlnn_asNoGTFile[] = $sGTFilePath;
}
unset($expGenMatch);
}
}
}
/*
* Taps are needed, so run through the ShortLinks GT files
*/
if (count($asGTFilePathTmp) > 0) {
$asGTFilePath = array_unique($asGTFilePathTmp);
foreach($asGTFilePath as $sGTFilePath) {
if ($sGTFilePath != '') {
if ($tlnn_bDebugMode) {
echo '[ShortLinks_PerformTap] = Using GT File :: ' . $sGTFilePath . '<br />';
}
unset($urlin, $urlout);
include($sGTFilePath);
$nextGenContent = preg_replace($urlin, $urlout, $nextGenContent);
} else {
if ($tlnn_bDebugMode) {
echo '[ShortLinks_PerformTap] = GT File :: ' . $sGTFilePath . ' :: Does Not Exist!<br />';
}
}
}
}
/*
* If there are still untapped links, if in debug mode, show the admin what modules are left which need GT/GTB files:
*/
if ($tlnn_bDebugMode && count($tlnn_asNoGTFile) > 0) {
foreach($tlnn_asNoGTFile as $sNoGTFile) {
if (!in_array($sNoGTFile, $tlnn_asGTFileExclude)) {
echo '[ShortLinks_UnShortenedLinks] = Consider creating GT/GTB File(s) :: ' . $sNoGTFile . '<br />';
}
}
}
$sFinishUpContent = ob_get_contents();
ob_end_clean();
echo $nextGenContent;
echo $sFinishUpContent;
return;
}
/**
* Function: tlnn_fShortenBlockURLs
*
* Takes the $content from an individual block (called from mainfile.php) and
* shortens the links using its corresponing GTB-<<block file name>>.php if one exists.
*
* @param string $sBlockfile is the name of the block file that is needing to be "tapped"
* @param string $sContents is the block HTML contents to have links shortened
* @return string the contents of the block with links shortened
*/
function tlnn_fShortenBlockURLs($sBlockfile = '', $sContents = '') {
global $tlnn_bDebugMode, $tlnn_sGTFileDir, $tlnn_asNoGTFile;
if ($tlnn_bDebugMode) {
echo '[ShortLinks_Function] = Present In Block<br />';
}
if ($sBlockfile != '') {
$sGTBlockPath = $tlnn_sGTFileDir . '/GTB-' . $sBlockfile;
if (@file_exists($sGTBlockPath)) { // Block has been "Tapped"
if ($tlnn_bDebugMode) {
echo '[ShortLinks_FilePath] = GTB File Exists for :: ' . $sBlockfile . '<br />';
}
tlnn_fCleanLinks($sContents);
unset($urlin, $urlout);
include_once($sGTBlockPath);
$sContents = preg_replace($urlin, $urlout, $sContents);
} else {
if ($tlnn_bDebugMode) {
echo '[ShortLinks_FilePath] = GTB File Does NOT Exist for :: ' . $sBlockfile . '<br />';
$tlnn_asNoGTFile[] = $sGTBlockPath;
}
}
} else {
if ($tlnn_bDebugMode) {
echo '[ShortLinks_Function] = In HTML Block<br />';
}
}
return $sContents;
}
/**
* Function: tlnn_fCleanLinks
*
* In order to find the necessary link patterns, ALL URLs must have a consistent usage
* of the "&", namely "&".
*
* $param string &$getNextGen is passed by reference for speed. This is for the string
* of HTML coming into the function.
* @return void the return is the variable passed by reference
*/
function tlnn_fCleanLinks(&$getNextGen) {
$getNextGen = preg_replace('(&(?!([a-zA-Z]{2,6}|[0-9\#]{1,6})[\;]))', '&', $getNextGen);
$getNextGen = str_replace(array(
'&&',
'&middot;',
'&nbsp;',
'&#'
), array(
'&&',
'·',
' ',
'&#'
), $getNextGen);
return;
}
?>
Return to Friendly URLs with Mod_Rewrite
Users browsing this forum: No registered users and 6 guests