Contents
A Simple Redirect
You can use .htaccess to redirect users to a different URL. The most basic .htaccess looks for any request for a specific page and if it finds that request, it forwards it to a new page. The syntax is:
redirect oldpage newpage
There are 3 parts:
redirect— The redirect command.oldpage— The old location you want redirected to somewhere else.newpage— The full URL of the location you want to send the user to.
These parts are separated by a single space and should be on one line.
For example, if you want to redirect users from oldpage.html in the root directory of your website to newpage.html, the syntax should be:
redirect /oldpage.html http://example.com/newpage.html
Anyone going to http://example.com/oldpage.html will be redirected to http://example.com/newpage.html.
You must use a full URL even if you’re going to send the users to another page on your own site.
You can also redirect an entire directory:
redirect /old_dir/ http://example.com/new_dir/
Anyone going to http://example.com/old_dir/filename.html will be redirected to http://example.com/new_dir/filename.html.
Redirecting a Tilde URL (i.e. /~account/) to a Virtual Host
Redirecting from One Domain to Another Domain
Redirecting by Dropping WWW from the Domain Name
Redirecting HTTP to HTTPS
Add the following rules to your .htaccess file to direct incoming requests from HTTP to HTTPS:
RewriteEngine On
RewriteCond %{HTTPS} !on$
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
