php - 301 redirection to changed urls
I need to change the domain name of my site and I will use permanent redirection 301. I found that this setup on .htaccess will do the job:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://www.new-example.com/$1 [L,R=301,NC]
But I also need to change all urls structure from http://www.new-example.com/old/this-is-url1.html to http://www.new-example.com/this-is-url1.html.
Rule must effect only urls with directoryold
on their alias: www.new-example.com/old/...
And redirect them to urls without directoryold
: www.new-example.com/
Can you please show me what redirect rule I must use on .htaccess to make this happen?
Answer
Solution:
Replace your shown code with this rule:
Clear your browser cache before testing this change.