Chris K
Chris K

Reputation: 3

htaccess 301 redirect rule for forum profile links

I switched forum platforms and I'd like to redirect requests to member profiles using a 301 redirect.

The old platform path to user profiles was: www.example.com/forum/member.php?u=XXXXXX The new platform path to user profiles is: www.example.com/user/XXXXXX

The user IDs have remained the same during the switch.

I tried to accomplish this by writing the following RewriteRule:

RewriteRule ^forum/member.php?u=(.*)$ http://www.example.com/user/$1 [R=301,L]

Unfortunately, it's not working for some reason and I can't figure out why. Any help would be greatly appreciated!

Thanks, -Chris

Upvotes: 0

Views: 144

Answers (1)

Ulrich Palha
Ulrich Palha

Reputation: 9509

You cannot access the query string from a RewriteRule directive.

Try the following instead.

#if the query string has a u parameter
RewriteCond %{QUERY_STRING} (^|&)u=([^&]+) [NC}
RewriteRule ^forum/member.php$ http://www.example.com/user/%2 [R=301,L]

Upvotes: 1

Related Questions