301 redirect help?

CLKeenan

Banned
Jun 24, 2006
2,506
14
0
Boston, MA
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: IANA — Example domains
The new platform path to user profiles is: IANA — Example domains

The user IDs have remained the same during the switch.

I tried to accomplish this by writing the following RewriteRule:

Rewr*teRule ^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
 


try:


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

I am assuming you turned the rewrite engine on.
 
this is just off the top of my head but try this:

Code:
RewriteEngine On
 RewriteCond %{QUERY_STRING} ^u=([0-9]*)$
 RewriteRule ^forum/member\.php$ http://www.example.com/user/%1 [R=301,L]
.htaccess is vodoo!!
 
^^ yeah, do it like this.^^

What you were doing could possibly capture other stuff in the URL, like additional variables in the query string, or not capture at all if the 'u' variable is not first.

And also, '?' and '.' are special characters.
 
this is just off the top of my head but try this:

Code:
RewriteEngine On
 RewriteCond %{QUERY_STRING} ^u=([0-9]*)$
 RewriteRule ^forum/member\.php$ http://www.example.com/user/%1 [R=301,L]
.htaccess is vodoo!!

+ on this.. Great way to handle the rewrite. If you are not sure if the u is going to be alone or first then you might consider this:

Code:
RewriteEngine On
 RewriteCond %{QUERY_STRING} u=([0-9]*)
 RewriteRule ^forum/member\.php$ http://www.example.com/user/%1 [R=301,L]

Just not sure if the variable has to be terminated with $ but I know ^ ensures that the query string starts with. I also believe the ^u=([0-9]*)$ will only redirect if the query exactly matches u=12345 with nothing before or after it in the query string. I could be wrong though. Regex isn't my forte.