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} ^ [NC,OR]
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301,NC]

But I also need to change all urls structure from to

Rule must effect only urls with directoryold on their alias:

And redirect them to urls without directoryold:

Can you please show me what redirect rule I must use on .htaccess to make this happen?




Replace your shown code with this rule:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(?:old/?)?(.*)$$1 [L,R=301,NC,NE]

Clear your browser cache before testing this change.

People are also looking for solutions to the problem: php - WordPress parent-child menu HTML


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.