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.
2 replies on “Handy htaccess file tips”
This is a very nice article on htaccess. you can generate htaccess file using this htaccess redirect generator. i like your article.
Hi Ejikeme,
I’ve not seen that page before, but will bookmark as it seems handy!!
Thanks