I’ve moved the files on my server to a new directory and would like to 301 redirect all the requests to the files in the new directory.
Say I have:
- domain.com/test/apples.php
- domain.com/test/oranges.php
- domain.com/test/bananas.php
How do I redirect them to:
- domain.com/apples.php
- domain.com/oranges.php
- domain.com/bananas.php
without having to redirect each one individually?
Assuming you’re using a server with mod_rewrite, In your root create a file named “.htaccess” and insert the following contents:
Note that this will rewrite every single file in the test directory to the domain you inserted.
If you only want to redirect .php files use:
NOTES:
Don’t forget to change the domain.com to your domain name, also this type of redirect will make a 301 redirect that is usefull for redirecting PERMANENTLY the url of a file (This will help search engines updating your links).