Why is this config code not working in .htaccess?

<VirtualHost *:80>
   DocumentRoot /lf/main/com 
   ServerName 74.220.215.241/~laborfa2 
   ServerAlias 74.220.215.241/~laborfa2 
   RewriteEngine on 
   #RewriteLogLevel 2 
   #RewriteLog logs/rewrite.log 
   RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.php -f 
   RewriteRule ^/(.*)(/?)$ /$1.php [L] 
    RewriteRule ^/([a-zA-Z]+)([a-zA-Z0-9_]{3,15})(/?)$ /profile.php?fairid=$1$2 [L] 
    RewriteRule ^/([a-zA-Z]+)([a-zA-Z0-9_]{3,15})/([a-z]*)(/?)$ /$3.php?fairid=$1$2 [L]     

 </VirtualHost> 

      

It works fine on linux (htt.vhost), but when I paste it .htaccess doesn't work.

So what do I need to change to make it work?

0


a source to share


5 answers


G'day,

As mentioned above, the context of the VirtualHost directive explicitly excludes its use in .htaccess files:

From the Apache 2.2 manual:



server config ... means that the directive can be used in server configuration files (for example, httpd.conf), but not inside any or containers. It is not allowed in .htaccess files at all.

NTN

amuses,

+2


a source


You cannot use a directive RewriteLog

in .htaccess file

. See Documentation mod_rewrite

. You should also look into the error log when you encounter such problems.



0


a source


You cannot set up a virtual host inside a virtual host.

0


a source


The block <VirtualHost>

you are using can only be configured inside the httpd.conf file (main server config) and will not work inside .htaccess .

You can try moving VirtualHost inside httpd.conf and just leving RewriteCond and RewriteRule inside .htaccess file.

0


a source


The ServerName directive must contain the server name, not the URL. Setting it to www.example.com:80 is valid, but www.example.com/~example is not. See Apache mod_core documentation.

In addition, even if the entry has been commented out, you cannot use the RewriteLog directive in the .htaccess file. See Apache mod_rewrite documentation.

0


a source







All Articles