重写具有%20的动态查询字符串

时间:2013-09-23 19:38:55

标签: regex .htaccess mod-rewrite url-rewriting

由于@anubhava,我有这些重写规则对我有用。

Options +FollowSymLinks -MultiViews
Turn mod_rewrite on
RewriteEngine On
RewriteBase /

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

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

我还需要在name参数中将%20替换为-Cristiano%20Ronaldo要重写为Cristiano-Ronaldo

我可以在上面的重写规则中制作它还是我需要做其他事情?

1 个答案:

答案 0 :(得分:0)

如果只有一个%20被替换,则以下内容将起作用:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+players/player\.php\?name=([^\%20]+)\%20([^&\s]+) [NC]
RewriteRule ^ Football-Players/%1-%2? [R=301,L]

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

RewriteRule ^Football-Players/([^-]+)-([^/-]+)/?$ players/player.php?name=$1\%20$2  [L,QSA,NC]

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