skip to Main Content

When I added the <VirtualHost> directive to the below .htaccess file, our production server news.XXX (I write XXX instead of our real domain name) fails with an internal error.

Please help to understand the reason of the error.

Header set X-UA-Compatible "IE=edge"
AddType text/html .html
AddType text/x-component .htc
AddHandler server-parsed .html .xml
Options -Indexes +Includes +ExecCGI
Order allow,deny
Allow from all


#<FilesMatch ".(xml|css|js)$">
#  ExpiresActive on
#  ExpiresDefault "access plus 15 minutes"
#</FilesMatch>

#<IfModule mod_expires.c>
#  ExpiresActive on
#  ExpiresDefault "access"
#  ExpiresDefault "access plus 15 minutes"
#  ExpiresByType text/html "access"
#  ExpiresByType text/plain "access"
#  ExpiresByType text/csv "access"
#  ExpiresByType application/xml "access"
#</IfModule>


RewriteEngine On

#DirectoryIndex /working-on-server.html
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^(.*)$ /working-on-server.html [L]

# Replaced real domain with XXX
<VirtualHost victor11.XXX>
DirectoryIndex /cgi-bin/news/index.NEW.fcgi
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /cgi-bin/news/index.NEW.fcgi [L,QSA]
</VirtualHost>

DirectoryIndex /cgi-bin/news/index.fcgi
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /cgi-bin/news/index.fcgi [L,QSA]

2

Answers


  1. The VirtualHost directive is only valid in the global server scope / in real configuration files. It’s not valid in htaccess or any other configuration sections.

    If you need virtual hosts, you ned to edit the configuration files read by Apache at startup.

    Each directive lists the context it’s valid for in the manual.

    Login or Signup to reply.
  2. VirtualHost directives cannot be used inside .htaccess files as Apache has already determined which VirtualHost is being used before including the .htaccess rules.

    You may want to do something like this if you have multiple VirtualHosts using the same public html folder:

    <If "req('Host') == 'new.example.com'">
        DirectoryIndex /cgi-bin/news/index.NEW.fcgi
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ /cgi-bin/news/index.NEW.fcgi [L,QSA]
    </If>
    <Else>
        DirectoryIndex /cgi-bin/news/index.fcgi
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ /cgi-bin/news/index.fcgi [L,QSA]
    </Else>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search