由于@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
。
我可以在上面的重写规则中制作它还是我需要做其他事情?
答案 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]