Php 如何使用htaccess将动态Url与静态Url匹配?

Php 如何使用htaccess将动态Url与静态Url匹配?,php,.htaccess,Php,.htaccess,我想知道如何使用htaccess将动态URL与静态URL相匹配。我的代码如下:- 我的php函数:- public static function ToTagLinks($tags, $page = 1){ $tags = explode(',', $tags); foreach ($tags as &$tag) { //$link ='tagged/'.self::CleanUrlText($tag); $link ='index.php?TagSearch

我想知道如何使用htaccess将动态URL与静态URL相匹配。我的代码如下:-

我的php函数:-

public static function  ToTagLinks($tags, $page = 1){
   $tags = explode(',', $tags); 
   foreach ($tags as &$tag) {
//$link ='tagged/'.self::CleanUrlText($tag);
      $link ='index.php?TagSearchResults&TagName='.self::CleanUrlText($tag) ;
      if($page > 1)
         $link .='&Page='.$page;
         $tag = '<a class="taglist" href="'.self::Build($link).
                          '" title="show post tagged ' . $tag . '">' . $tag . '</a>';
   }
   return  implode(', ', $tags);            
}
公共静态函数ToTagLinks($tags,$page=1){
$tags=分解(“,”,$tags);
foreach($tags as&$tag){
//$link='taged/'.self::CleanUrlText($tag);
$link='index.php?标记搜索结果&标记名='.self::CleanUrlText($tag);
如果($page>1)
$link.='&Page='.$Page;
$tag='';
}
返回内爆(“,”,$tags);
}
我的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 /rswebtek_blog

# Rewrite to correct domain to avoid canonicalization problems
# RewriteCond %{HTTP_HOST} !^www\.example\.com
# RewriteRule ^(.*)$ http://www.example.com/$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-([0-9]+)/?$ index.php?TagSearchResults&TagName=$1&Page=$2[L]
RewriteRule ^tagged/?(.*)//?$ index.php?TagSearchResults&TagName=$1&Page=1 [L]

# 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

#启用mod_重写
重新启动发动机
#指定应用程序所在的文件夹。
#如果应用程序位于根目录中,则使用/。
RewriteBase/rswebtek_博客
#重写到正确的域以避免规范化问题
#重写cond%{HTTP_HOST}^www\.example\.com
#重写规则^(.*)$http://www.example.com/$1[R=301,L]
#将以/index.php或/index.html结尾的URL重写为/
RewriteCond%{THE_REQUEST}^GET\.*/index\(php | html?)\HTTP
重写规则^(.*)索引\(php | html?$$1[R=301,L]
#重写类别页面
重写规则^.*-c([0-9]+)/page-([0-9]+)/?$index.php?CategoryId=$1&page=$2[L]
重写规则^.*-c([0-9]+)/?$index.php?CategoryId=$1[L]
#重定向搜索结果
重写规则^search results/find-(.*)/page-([0-9]+)/?$index.php?SearchResults&SearchString=$1&page=$2[L]
重写规则^search results/find-?(.*)/?$index.php?SearchResults&SearchString=$1&Page=1[L]
#重定向标记搜索结果
重写规则^taged/(.*)/page-([0-9]+)/?$index.php?TagSearchResults&TagName=$1&page=$2[L]
重写规则^tagged/?(.*)/?$index.php?TagSearchResults&TagName=$1&Page=1[L]
#重写主页的子页面
重写规则^page-([0-9]+)/?$index.php?page=$1[L]
#重写帖子详细信息页面
重写规则^.*-p([0-9]+)/?$index.php?PostId=$1[L]
#为Apache错误设置默认的500页
ErrorDocument 500/rswebtek_blog/500.php
#设置defualt 404错误页面
ErrorDocument 404/rswebtek_blog/404.php
我的其他链接工作正常,但标记搜索链接的代码工作不正常404.php错误发生,但如果我使用动态url,则其工作正常。

尝试以下两条规则:

#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]

Anubhava Ji在我的上述链接函数中,我只想添加这种类型的链接www.example.com/taged/php,但我的动态url是index.php?TagSearchResults&TagName=phpAnubhava我编辑了我的上述代码非常感谢您的代码运行良好。请问我的代码有什么问题?这是一个正则表达式问题。您在regex模式中使用了
*
/