首页 > 解决方案 > 在 2 个路径之间重写查询字符串

问题描述

我是 .htaccess 的新手,所以希望有人可以帮助我。

我正在尝试重定向这些:

clan.php/tagID=clanstag
clanRatings.php/tagID=clanstag

对此:

/clan/clanstag
/clan/clanstag/ratings

到目前为止,我已经正确重定向了 clan.php,但我无法让 clanRatings.php 正确重定向。它一直认为 Clans 标签是 clantag/ratings。

这是我现在使用的代码:

# Rewrite clan.php
   RewriteEngine On
#url redirection from old url to the new one
#redirect /clan.php?tagID=TAG to /clan/TAG
   RewriteCond %{THE_REQUEST} /clan.php\?tagID=([^\s]+) [NC]
   RewriteRule ^.+$ /clan/%1? [L,R]
#url rewiring from new url to the old one
# rewrite /clan/TAG to /clan.php?tagID=TAG
   RewriteRule ^clan/(.*)$ clan.php?tagID=$1 [L]

# Rewrite clanRatings.php
   RewriteEngine On
#url redirection from old url to the new one
#redirect /clanRatings.php?tagID=TAG to /clan/TAG/ratings
   RewriteCond %{THE_REQUEST} /clanRatings.php\?tagID=([^\s]+) [NC]
   RewriteRule ^.+$ /clan/%1?/ratings [L,R]
#url rewiring from new url to the old one
# rewrite /clan/TAG/ratings to /clanRatings.php?tagID=TAG
   RewriteRule ^clan/(.*)$/ratings clanRatings.php?tagID=$1 [L]

在此先感谢您的帮助!

标签: phpapache.htaccessquery-string

解决方案


推荐阅读