views:

666

answers:

2

Hello, I need to use .htaccess file to replace a world in URL

something like this:

example URL: http://example.com/oldword/test-page.html

redirect to: http://example.com/newword/test-page.html

how can I use mod_rewrite to redirect every URL containt "/oldword/" to the same URL after replacing that word?

+4  A: 

This should do it for you:

RewriteRule ^oldword/(.*)   /newword/$1   [L]

Edit: It might not work exactly depending on your RewriteBase settings, but it'll be close.

Second Edit: If you need to have a 301 Moved Permanently header associated with the old URLs, you can do something like this as well:

RewriteRule ^oldword/(.*)   /newword/$1   [R=301,L]
zombat
+1  A: 

Hi,

see here:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^oldword(.*)$ http://%{HTTP_HOST}/newword$1 [L]
</IfModule>

ciao,

Chris

3DH
It’s better to leave the protocol, host and port part away like zombat did. Additionally your rule would also redirect `/oldword-and-some-more` to `/newword-and-some-more` and I don’t think that’s what chiaf wanted.
Gumbo