htaccess Redirect File Or Directory

Print Friendly

If you moved files from one directory or changed directory location, you will find it useful to redirect all your visitors to the true directory that contains all the files in it . Apache server was designed to allow manually redirection of all your traffic from “wrong” directory to the true directory, this method is also excellent for SEO practice, wrong pages will not been cached by search engines.

Here is .htaccess code for this task :

redirect 301 /oldfiles/mypage.html

We used 301 redirect command to redirect one file from one directory to another , and you should specify your “wrong” path  (/oldfiles/mypage.html) and “true” path

Sometimes we will throw our traffic to the new directory permanently , and here is .htaccess code

Redirect permanent /oldfiles/

You can modify your .htaccess file in your free time.