Monday, July 18, 2016

.htaccess Redirection Rule

This .htaccess file will redirect http://example.com/folder1/ to http://example.com/folder2/. Choose this version if you don't have the same file structure in both directories:
Filename: .htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^folder1.*$ http://example.com/folder2/ [R=301,L]
  • This .htaccess file will redirect http://example.com/folder1/ to plain http://example.com/. Choose this version if you want people redirected to your home page, not whatever individual page in the old folder they originally requested:
Filename: .htaccess.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^folder1.*$ http://example.com/ [R=301,L]
  • This .htaccess file will redirect http://example.com/folder1/file.html tohttp://example.com/folder2/file.html. Choose this version if your content is duplicated in both directories:
File name: .htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^folder1/(.*)$ http://gs.mt-example.com/folder2/$1 [R=301,L]

Test

Upload this file to folder2 (if you followed the first or third example) or your html folder (if you followed the second example) with FTP:
Filename: index.html
<html>
<body>
Mod_rewrite is working!
</body>
</html>
Then, if you followed the first or second example, visit http://example.com/folder1/ in your browser. You should see the URL change to http://example.com/folder2/ orhttp://example.com/ and the test page content.
If you followed the third example, visit http://example.com/folder1/index.html. You should be redirected to http://example.com/folder2/index.html and see the test page content.

No comments:

Post a Comment