WWW & HTTPS Redirects
Redirects are an important factor when finalising the last elements of your website launch. The domain will work across both the www and non-www versions. This means every site has two routes per domain, which can be used to access your site. Search engines, including Google, will treat these domains as separate websites. This will work negatively against your ranking, as search engines will perceive it as duplicated content across a number of sites.
In order to prevent this from happening, it’s necessary to set up 301 redirects. This can be done in your .htaccess file. If you are unsure about how to write redirects here is a good generator to help you, http://www.htaccessredirect.net/.
If you have SSL on your site, you will want to force users onto the secure URL (https) in order to make use of your secure connection. When using SSL, a simple htaccess generator probably won’t have all the options you will require — but have no fear as we have prepared a code snippet for you that should do the trick! This snippet also takes advantage of wildcards which means the file path (/resources/important-files/file.txt for example) is carried over to the redirected URL.
We have prepared two versions of the code for you depending on how you would like your domain to look. Simply pick one and replace YOURDOMAIN with your actual site domain.
This snippet reditects (http://) to (https://) and (www.domain.com) to (domain.com):
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.YOURDOMAIN.com
RewriteRule (.*) http://YOURDOMAIN.com/$1 [R=301,L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://YOURDOMAIN.com/$1 [R=301,L]
This snippet reditects (http://) to (https://) and (domain.com) to (www.domain.com):
RewriteEngine on
RewriteCond %{HTTP_HOST} ^YOURDOMAIN.com
RewriteRule (.*) http://www.YOURDOMAIN.com/$1 [R=301,L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.YOURDOMAIN.com/$1 [R=301,L]
Recent Comments