Redirect Generator
.htaccess Redirection Tutorial
Using .htaccess we can redirect from file or directory to other file, to other directory, or to other domain.
It is useful if you move your old file or old directory to new location. In order to use redirection, apache mod_alias should be active.
Basic Redirection
The basic use of redirection as follows:
Redirect FROM TO
From may be the directory name or file name, e.g:
old_file.html or
/very/old_directory/
To should be in URL or URL-path beginning with a slash , e.g:
http://www.domain.com/new_directory/ or
/new_directory/new_file.html
Redirect from old file to new file
Redirect old_file.html http://www.yourdomain.com/new_file.html
or
Redirect old_file.html /new_file.html
Redirect from old directory to new directory
Redirect /old_directory http://www.yourdomain.com/new_directory/
or
Redirect from old directory to new directory
Redirect /old_directory /new_directory
301 - Permanent Redirection
Permanent 301 redirect is the most efficient and search engine friendly method for webpage redirection.
You can use following code to permanent redirect your page or directory:
Redirect permanent /old_file.html http://www.yourdomain.com/new_file.html
or
Redirect 301 /old_file.html http://www.yourdomain.com/new_file.html
Redirect Old Domain to New Domain
To redirect old domain requests to new domain, you can use the following code:
RedirectMatch ^(.*)$ http://www.anotherserver.com$1
or you can use mod_rewrite
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.:]+\.)*old-domain\.com\.?(:[0-9]*)?$ [NC]
RewriteRule ^(.*)$ http://www.new-domain.com/$1 [R=301,L]
302 - Temporary Redirection
If you want to create temporary redirection you can use the following code:
Redirect temp /old_file.html http://www.yourdomain.com/new_file.html
or
Redirect 302 /old_file.html http://www.yourdomain.com/new_file.html