Tuesday, May 3, 2011

.htaccess redirect after replace a word?

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?

From stackoverflow
  • 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]
    
  • Hi,

    see here:

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

    ciao,

    Chris

    Gumbo : 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.

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.