1

I have these rewrite rules that work for me thanks to @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]

I need also to replace %20 to - in the name parameter. Cristiano%20Ronaldo to be rewritten to Cristiano-Ronaldo.

Can I make it in the rewrite rule above or I need to do something else?

4

1 回答 1

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]
于 2013-09-23T20:10:25.303 回答