Categories
HowTo Guides Plesk

Handy htaccess file tips

Ok – here is some handy .htaccess bits

If you want to redirect all visitors to a single page, apart from specific IP address (eg your IP or your customers) the following .htaccess file can be used. Simply repeat the REMOTE_ADDR line if you want more IP addresses :

<IfModule mod_rewrite.c>
  RewriteCond %{REMOTE_ADDR} !^82\.16\.14\.130
  RewriteCond %{REMOTE_ADDR} !^82\.87\.43\.123
  RewriteCond %{REQUEST_URI} !/comingsoon.html$ [NC]
  RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
  RewriteRule .* /comingsoon.html [R=302,L]
</IfModule>

What about if you want to use Google’s ‘site moved’ facilities, and you already have your 301 redirect in place? When you try to validate your domain with Google it will fail! So… using this .htaccess file, you can redirect all traffic to your new domain, but still let Google access your validation file :

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTP_HOST} yourolddomain.co.uk [NC]
  RewriteCond %{REQUEST_URI} !^/google1d5jdk4533a39485.html$
  RewriteRule ^(.*)$ http://www.yournewdomain.co.uk/$1 [R=301,L]
</IfModule>

If you have any .htaccess tips – please leave a comment, and I’ll add them to the list.