How to rewrite/replace single parameter with 301 redirect?

I changed a username and would like to 301 redirect all user pages to the new one.

Old URLs:
http://www.mysite.com/OLDname/stuff/blah/things/hams/

New URLs:
http://www.mysite.com/NEWname/stuff/blah/things/hams/

How is this done?

Thanks

peppy,

Okay, that’s STILL not your .htacess but I can guess at that (and suggest that your RewriteRule be modified to get rid of the leading / if (and ONLY IF) you’re using an Apache 2.x server - the / is required by Apache 1.x but rejected by Apache 2.x.

Now, to change

http://www.mysite.com/OLDname/stuff/blah/things/hams/
http://www.mysite.com/NEWname/stuff/blah/things/hams/

the simple way is to use mod_alias (Apache core) with

Redirect /OLDname/ /NEWname/

as the link above showed, all subdirectories (path/file) following OLDname will be sent to NEWname/, too.

BECAUSE you’re already using mod_rewrite, however, you could PRECEDE the existing mod_rewrite code with

RewriteRule ^/?OLDname/(.*)$ NEWname/$1 [L](

Just know that (.*) (ZERO or more of ANYTHING) is a CAPTURE ALL (garbage collector) and should be replaced with ([a-zA-Z]+) (one or more characters). Placing it BEFORE your existing code will change the {REQUEST_URI} string so NEWname will be served rather than OLDname.

Regards,

DK

peppy,

Hmmm, you’ve just said a mouthful without saying anything at all. Please show your current .htaccess and what CMS you’re using. Obviously, something missing in what you’re telling us so that may help.

Regards,

DK

peppy,

Apache’s mod_alias is designed for just that task!

Regards,

DK

Greetings dklynn,

Basically with the two URLS at the top:
http://www.mysite.com/OLDname/stuff/blah/things/hams/
http://www.mysite.com/NEWname/stuff/blah/things/hams/

They are the final results of a mod_rewrite similar to this:
RewriteRule ^/([^/]*)/stuff/blah/things/hams/$ /member.php?membername=$1 [L]

I’m using $_GET[‘membername’] to pull the username to put inside the membername parameter, which is then used to access information from a MySQL database.

When I changed the username in the database, everything works fine for NEWname but now I’m getting a lot of “not found” errors in Google Webmaster tools for the urls that had /OLDname/ in them.

Let me know you know what I’m talking about or how I can 301 redirect the old urls to the new ones. (basically the only difference is the username in the URLs)

Thanks

Thanks

Thanks for providing this page. Could you please provide an example code for the above example? I keep getting server 500 errors.

Also, those URLs above are the end product of the URL re-write mod. For example ?membername=OLDname gets rewritten to /OLDname/.