Search code examples
.htaccesshttp-redirectpermalinks

How To Redirect with modified URL using .htacess


I want to move my website to a new domain. But, facing a problem with Permalink structure. Example,

Old Structure: oldsite.com/salman-khan-biography/
New Structure: newsite.com/salman-khan-movies/

Actually, just single word will be changed from the end of permalinks. I tried below codes, but it's showing 404 not found on the new domain.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^oldsite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^(.*)$ http://newsite.com/$1 [L,R=301,NC]

Solution

  • Try with below in your old website htaccess.

    RewriteEngine On
    RewriteCond %{REQUEST_URI} (.+)\-biography/?$
    RewriteRule ^ http://newsite.com/%1-movies/ [R=301]