.htaccess 301 redirect Apache


.htaccess 301 redirect Apache

这个重写规则真的有问题

RewriteRule ^index.php?a=profile&u=(.*)$ /profile/$1 [R=301]

我想让301重定向像mysite.com/profile/USERNAME

Querystring不是RewriteRule中匹配的一部分,您需要在RewriteCond中与%{THE_REQUEST} var匹配,然后使用%n来获得匹配:

这应该是你完整的htaccess:

RewriteEngine on
RewriteCond %{THE_REQUEST} /index'.php'?a=profile&u=([^'s]+) [NC]
RewriteRule ^ /profile/%1? [L,R]
RewriteRule ^profile/([^/]+)/?$ /index.php?a=profile&u=$1 [NC,L]

尝试

RewriteCond %{QUERY_STRING} ^a=profile&u=(.*)$
RewriteRule ^index.php /profile/%1 [L,R]