在具有相同字符串值的两个不同页面上重写动态查询字符串

时间:2014-02-03 17:50:00

标签: php .htaccess mod-rewrite url-rewriting wampserver

您好我的问题是重写具有相同查询值的两个不同页面的URL 示例:/players.php?name=Messi/clubs.php?name=Barcelona

我的.htaccess是:

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+club\.php\?name=([^&\s]+) [NC]
RewriteRule ^ /%1-Football-Wallpapers? [R=301,L] 
RewriteRule ^/([^/]+)-Football-Wallpapers/?$ /club.php?name=$1 [L,QSA,NC]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+player\.php\?name=([^&\s]+) [NC]
RewriteRule ^ /%1-Football-Wallpapers? [R=301,L] 
RewriteRule ^([^/]+)-Football-Wallpapers/?$ /player.php?name=$1 [L,QSA,NC]<br>

如果我只使用其中一条规则, club.php?name = barcelona 页面的所有内容都可以,但是当我同时使用它们时,我会尝试打开 player.php? name = messi 我会重定向到 club.php
是否有可能在我使用的旗帜中出错?

1 个答案:

答案 0 :(得分:0)

您对2个不同的网页有相同的规则。重写引擎没有任何区别,它需要第一个(这里是club.php)

一个简单的例子是在玩家规则中添加一些内容:

RewriteRule ^([^/]+)-Football-Wallpapers-Player/?$ /player.php?name=$1 [L,QSA,NC]

现在您有一个内部重定向,从Football-Wallpapersclub.phpFootball-Wallpapers-Playerplayer.php