当我在下面选择一类帖子时,我有重定向循环是我的htaccess文件: -
<IfModule mod_rewrite.c>
# Enable mod_rewrite
RewriteEngine On
# Specify the folder in which the application resides.
# Use / if the application is in the root.
RewriteBase /
# Rewrite to correct domain to avoid canonicalization problems
RewriteCond %{HTTP_HOST} !^www\.rswebtek\.in
RewriteRule ^(.*)$ http://www.rswebtek.in/$1 [R=301,L]
# Rewrite URLs ending in /index.php or /index.html to /
RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php|html?)\ HTTP
RewriteRule ^(.*)index\.(php|html?)$ $1 [R=301,L]
# Rewrite category pages
RewriteRule ^.*-c([0-9]+)/page-([0-9]+)/?$ index.php?CategoryId=$1&Page=$2 [L]
RewriteRule ^.*-c([0-9]+)/?$ index.php?CategoryId=$1 [L]
#Redirect search results
RewriteRule ^search-results/find-(.*)/page-([0-9]+)/?$ index.php?SearchResults&SearchString=$1&Page=$2[L]
RewriteRule ^search-results/find-?(.*)//?$ index.php?SearchResults&SearchString=$1&Page=1 [L]
#Redirect tag search results
RewriteRule ^tagged/([^/]+)/page-(\d+)/?$ index.php?TagSearchResults&TagName=$1&Page=$2 [L,QSA]
RewriteRule ^tagged/([^/]+)/?$ index.php?TagSearchResults&TagName=$1&Page=1 [L,QSA]
#Redirect static pages based on page name
RewriteRule ^pages/([^/]+)/?$ index.php?StaticPage&PageName=$1 [L,QSA]
# Rewrite subpages of the home page
RewriteRule ^page-([0-9]+)/?$ index.php?Page=$1 [L]
# Rewrite Post details pages
RewriteRule ^.*-p([0-9]+)/?$ index.php?PostId=$1 [L]
</IfModule>
# Set the default 500 page for Apache errors
ErrorDocument 500 /rswebtek_blog/500.php
#Set the defualt 404 error page
ErrorDocument 404 /rswebtek_blog/404.php
这是我的link.php文件: -
<?php
class Link{
public static function Build($link, $type='http'){
$base = (($type == 'http' || USE_SSL == 'no') ? 'http://' :'https://').getenv('SERVER_NAME');
//if HTTP_SERVER_PORT is defined and different than default
if(defined('HTTP_SERVER_PORT') && HTTP_SERVER_PORT !='80' && strpos($base, 'https') === false){
//append server port
$base .=':' . HTTP_SERVER_PORT;
}
$link = $base . VIRTUAL_LOCATION . $link;
//escape html
return htmlspecialchars($link, ENT_QUOTES);
}
public static function ToCategory($categoryId, $page =1){
$link = self::CleanUrlText(Blog::GetPostCategoryName($categoryId)).
'-c'.$categoryId.'/';
//$link ='index.php?CategoryId='.$categoryId;
if($page > 1)
$link .='page-'.$page.'/';
//$link .= '&Page='.$page;
return self::Build($link);
}
public static function ToPost($postId){
$link = self::CleanUrlText(Blog::GetPostTitle($postId)).
'-p'.$postId.'/';
// return self::Build('index.php?PostId='.$postId);
return self::Build($link);
}
public static function ToIndex($page = 1){
$link ='';
if($page > 1)
$link .='page-'.$page.'/';
//$link .='index.php?Page='.$page;
return self::Build($link);
}
public static function QueryStringToArray($queryString){
$result = array();
if($queryString !=''){
$elements =explode('&',$queryString);
foreach($elements as $key => $value){
$element = explode('=',$value);
$result[urldecode($element[0])] = isset($element[1]) ? urldecode($element[1]) : '' ;
}
}
return $result;
}
// Prepares a string to be included in an URL
public static function CleanUrlText($string)
{
// Remove all characters that aren't a-z, 0-9, dash, underscore or space
$not_acceptable_characters_regex = '#[^-a-zA-Z0-9_ ]#';
$string = preg_replace($not_acceptable_characters_regex, '', $string);
// Remove all leading and trailing spaces
$string = trim($string);
// Change all dashes, underscores and spaces to dashes
$string = preg_replace('#[-_ ]+#', '-', $string);
// Return the modified string
return strtolower($string);
}
//redirects to proper url if not already there
public static function CheckRequest(){
$proper_url = '';
if (isset ($_GET['Search']) || isset($_GET['SearchResults']) || isset($_GET['TagSearchResults']) || isset($_GET['StaticPage'])){
return;
}
// Obtain proper URL for category pages
elseif (isset ($_GET['CategoryId'])){
if (isset ($_GET['Page']))
$proper_url = self::ToCategory($_GET['CategoryId'], $_GET['Page']);
else
$proper_url = self::ToCategory($_GET['CategoryId']);
}
// Obtain proper URL for post pages
elseif (isset ($_GET['PostId'])){
$proper_url = self::ToPost($_GET['PostId']);
}
// Obtain proper URL for the home page
else{
if (isset($_GET['Page']))
$proper_url = self::ToIndex($_GET['Page']);
else
$proper_url = self::ToIndex();
}
/* Remove the virtual location from the requested URL
so we can compare paths */
$requested_url = self::Build(str_replace(VIRTUAL_LOCATION, '',$_SERVER['REQUEST_URI']));
//404 redirect if the requested product, category or department
//donnot exist
if(strstr($proper_url, '/-')){
//clean output buffer
ob_clean();
//load the 404 page
include('404.php');
//clear the output buffer an stop executon
flush();
ob_flush();
ob_end_clean();
exit();
}
// 301 redirect to the proper URL if necessary
if ($requested_url != $proper_url){
// Clean output buffer
ob_clean();
// Redirect 301
header('HTTP/1.1 301 Moved Permanently');
header('Location:'.$proper_url);
// Clear the output buffer and stop execution
flush();
ob_flush();
ob_end_clean();
exit();
}
}
//create link to the search page
public static function ToSearch(){
return self::Build('index.php?Search');
}
public static function ToSearchResults($searchString, $page = 1){
$link = 'search-results/find';
if(empty($searchString))
$link .='/';
else
$link .= '-' . self::CleanUrlText($searchString) . '/';
// $link .='all-words-'.$allWords.'/';
if($page > 1)
$link .= 'page-'.$page.'/';
return self::Build($link);
}
//build tag links
public static function ToTagLinks($tags, $page = 1){
$tags = explode(',', $tags);
foreach ($tags as &$tag) {
$link ='tagged/'.self::CleanUrlText($tag) ;
if($page > 1)
$link .='/page-'.$page.'/';
$tag = '<a class="taglist" href="'.self::Build($link).'" title="">'.$tag.'</a>';
}
return implode(', ', $tags);
}
public static function ToStaticPage($pageName){
//$link ='index.php?StaticPage&PageName='.$pageName;
$link ='pages/'.self::CleanUrlText($pageName) ;
return self::Build($link);
}
public static function ToTagNexPreLink($tag, $page = 1){
$link ='tagged/'.self::CleanUrlText($tag) ;
if($page > 1)
$link .='/page-'.$page.'/';
return self::Build($link);
}
?>
和index.php
<?php
//active session
session_start();
//start output buffer
ob_start();
//include utility files
require_once('include/config.php');
require_once(BUSINESS_DIR.'error_handler.php');
//set error handler
ErrorHandler::SetHandler();
// Load the database handler
require_once BUSINESS_DIR . 'database_handler.php';
// Load Business Tier
require_once BUSINESS_DIR . 'blog.php';
//Link::CheckRequest();
// Load presentation Tier
require_once(PRESENTATION_DIR.'application.php');
require_once(PRESENTATION_DIR.'link.php');
Link::CheckRequest();
$application = new Application();
//this is used to mute errors
$application->muteExpectedErrors();
//display page
$application->display('blog_front.tpl');
// close the connection
DatabaseHandler::Close();
//output content from the buffer
flush();
ob_flush();
ob_end_clean();
?>
当我选择一个类别或帖子时出现问题: - 我的静态链接如下
http://www.rswebtek.in/database-c3/
任何帮助必须得到赞赏