Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm upgrading a website and I use this .htaccess file to show maintenance page:

#MAINTENANCE-PAGE REDIRECT
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.0 # Bogus IP address for posting here
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.0 # Bogus IP address for posting here
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://www.mysite.no/maintenance.html [R=307,L]

This opens the maintenance page for all users except the two IP addresses I've added. They get an Internal Server Error. I've used thesame script on another site, and that worked fine.

Looking at the error log, I see the following:

/var/www/vhosts/mysite.no/httpdocs/.htaccess: RewriteCond: bad flag delimiters 

If I remove my .htaccess file, I can work with my site just fine.

My site is hosted on a VPN using CentOS 5.

How can I fix this problem?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

I believe you have to use the [OR] flag to chain rules like this:

#MAINTENANCE-PAGE REDIRECT
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.0 [OR]
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.0 [OR]
RewriteCond %{REQUEST_URI} !^/maintenance\.html$ 
RewriteRule ^(.*)$ http://www.mysite.no/maintenance.html [R=307,L]

In the apache docs, it's at the bottom of this section as an example: http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond

Also, you can use the RewriteLog and RewriteLogLevel 3 directives to possibly gain some more insight.

share|improve this answer
    
Thanks, you led me to the answer. Actually it was the # comment behind the two lines that caused the error. Not sure why. But removing these fixed it. –  Steven Nov 2 '10 at 21:30
    
@Steven: I belive line-end comments were once supported but since around Apache 1.3.22 they were removed. Full line comments only. –  w3d Aug 9 '13 at 16:45

Some things to try/check:

  • Make sure mod_rewrite is loaded and enabled in apache.
  • Make sure the FileInfo override is allowed (with AllowOverride) for .htaccess files.
  • Remove the comments from your RewriteCond lines.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.