Your .htaccess file is commonly used to change the way that people access or view your site. This can be particularly important if you change the structure of your site and need to "redirect" visitors to where the content is now stored.
Please note that we do not support custom coding and these examples are given for your reference only. A "Google search" will return many more examples.
# Never use www in the domain. Replace 'example.com' with your domain nameRewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?example\.com)$ [NC]
RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]
# Always use www in the domain. Replace 'example.com' with your domain nameRewriteEngine on
RewriteCond %{HTTP_HOST} ^([a-z.]+)?example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .? http://www.%1example.com%{REQUEST_URI} [R=301,L]
#Specify a default home page (index page)DirectoryIndex home.html
#Block specified IPs from accessing your siteRequire all granted
Require not ip 125.0.0.1
Require not ip 125.0.0.2
Require not ip 125.0.0.3
#Allow only specified IPs to access your siteRequire ip 125.0.0.4
Require ip 125.0.0.5
# Redirect all pages from olddomain.com to newdomain.comOptions +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^olddomain.com$
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
# Set a default home directory, (instead of your website root). Replace 'folder' with your subfolder nameRewriteEngine On
RewriteRule ^$ /folder/ [R=301,L]
# Rename a directory and force visitors to the new name. Replace 'old' with your old folder name. Replace 'new' with your new folder nameRewriteEngine on
RewriteRule ^/?old([a-z/.]*)$ /new$1 [R=301,L]
# Always use https for secure connections. Replace 'www.example.com' with your domain name (as it appears on your SSL certificate)RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
# Block traffic from unwanted referrersRewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} badsite\.com [NC,OR]
RewriteCond %{HTTP_REFERER} badforum\.com [NC,OR]
RewriteCond %{HTTP_REFERER} badsearchengine\.com [NC]
RewriteRule .* - [F]
#Do not allow these file types to be calledRewriteEngine on
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|exe|swf)$ - [F,NC]