How do I redirect my site using a .htaccess file?
November21
As a configuration file, .htaccess is very powerful. Even the slightest syntax error can result in your content not displaying correctly or at all.
Check the mostly used ones:
- Point an entire site to a different URL, such as domain.net redirected to domain.com:
# This allows you to redirect your entire website to any other domain Redirect 301 / http://kb.mediatemple.net/ - Redirect index.html to a specific subfolder:
# This allows you to redirect index.html to a specific subfolder Redirect /index.html http://mt-example.com/newdirectory/ - Redirect an old file to a new file path:
# Redirect old file path to new file path Redirect /olddirectory/oldfile.html http://mt-example.com/newdirectory/newfile.html - Redirect to a specific index page:
# Provide Specific Index Page (Set the default handler) DirectoryIndex index.html - Redirect users to access the site without www:
# To redirect all users to access the site WITHOUT the www. prefix, # (http://www.example.com/... will be redirected to http://example.com/...) # adapt and uncomment the following: RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.mt-example\.com$ [NC] RewriteRule ^(.*)$ http://mt-example.com/$1 [L,R=301] - Redirect users to use www:
# To redirect all users to access the site WITH the www. prefix, # (http://example.com/... will be redirected to http://www.example.com/...) # adapt and uncomment the following: RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.mt-example\.com$ [NC] RewriteRule ^(.*)$ http://www.mt-example.com/$1 [L,R=301]























