Working with .htacess
file has always been a very frustrating experience for me. Someone please help.
This is what I want to achieve:
- I am running Ubuntu 14.04.
- Redirect my entire site
(example.com)
to amaintenance.html
page. - Block everybody else except one IP, for example, I need to allow only
123.456.789.0
Here are my files:
- Location of my
index.html
is/var/www/html
- Location of my
maintenance.html
is/var/www/html
- Location of my
.htaccess
file is/var/www/html
Contents of My .htaccess
file:
#Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com[nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc]
#301 Redirect Old File
Redirect 301 /index.html /maintenance.html
#Block users by IP
order allow,deny
deny from all
allow from 123.456.789.0
Please help me understand:
- Is the location of each of the above files right? In what cases, the
page ends up in
500 internal server error
? - What changes should I make in
/etc/apache2/apache.conf
/etc/apache2/sites-enabled/000-default.conf
OR/etc/apache2/sites-available/000-default.conf
- Is is necessary to run
a2enmod rewrite
? - Should I add
<IfModule mod_rewrite.c>
and</IfModule>
as header and footer in any of the aboveconfig
files?
Sorry for too many questions, but I really want know it all this time. Thanks in advance.