IfThenElse
IfThenElse

Reputation: 509

Correct use of redirect in htaccess file

I need to redirect access from my old website (https://myweb/) in the respective pages of the new website (https://myweb/new). So I change my https://myweb/.htaccess file:

Redirect 301 /contact https://myweb/new/contact-us
Redirect 301 /blog https://myweb/new/my-blog
....

I think the redirect work like a if then exit:

if page is "/contact" then open https://myweb/new/contact-us and exit

After those rows I write some code to redirect request in "else" statment:

RewriteRule (.*) https://myweb/new/ [R=301,L]

Is it the correct solution?

Upvotes: 1

Views: 50

Answers (1)

anubhava
anubhava

Reputation: 785038

Have it this way:

RewriteEngine On

RewriteRule ^contact(.*)$ /new/contact-us$1 [L,NC,R=301]

RewriteRule ^blog(.*)$ /new/my-blog$1 [L,NC,R=301]

RewriteRule !^new/ /new%{REQUEST_URI} [L,NC,R=301]

Make sure to test if after clearing your browser cache.

Upvotes: 1

Related Questions