em.rexhepi
em.rexhepi

Reputation: 289

htaccess redirect to old website

I changed my whole website with a new once, but now I don't want to lose all the traffic that is coming from google. So i changed the old websites folder to www.domain.com/old/ and there are all of my articles.

How can i redirect from htaccess all the error 404 links on the new website to the old website.

Example:

The link request is www.domain.com/article29384.html and it causes error 404, now i want the htaccess to redirect it to www.domain.com/old/article29384.html

Solution: (thanks to anubhava)

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/old/ [NC]
RewriteRule ^(.+?)$ /old/$1 [NC,L,R=301]

Upvotes: 1

Views: 53

Answers (1)

anubhava
anubhava

Reputation: 785471

Put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/old/ [NC]
RewriteRule ^(.+?\.html)$ /old/$1 [NC,L,R=301]

Upvotes: 2

Related Questions