views:

136

answers:

6
<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 in .htaccess does not works.

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

A: 

You cannot use the RewriteLog directive in a .htaccess file. See the mod_rewrite documentation. You should also take a look in the error log when you run into such problems.

Martin Geisler
A: 

You cannot setup a vitual host inside a virtual host.

Gumbo
What i will use for running above code using .htaccess?because i am transferring my site from linux to shared server.For example.for What i use for "Document_Root"
A: 

The <VirtualHost> block that 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 the VirtualHost inside httpd.conf and just leving RewriteCond and RewriteRule inside the .htaccess file

duckyflip
What i will use for running above code using .htaccess?because i am transferring my site from linux to shared server.For example.for What i use for "Document_Root"?
A: 

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

Other than that, even though the entry has been commented out, you can't use the RewriteLog directive in an .htaccess file. See the Apache mod_rewrite documentation.

nilicule
A: 

VirtualHost can't be defined in .htaccess

<VirtualHost>  directive
Syntax: <VirtualHost addr[:port] [addr[:port]] ...> ... </VirtualHost>
Context: server config 
Status: Core.
Compatibility: Non-IP address-based Virtual Hosting only available in Apache 1.1 and later.
Compatibility: Multiple address support only available in Apache 1.2 and later.

Context: server config // that means only httpd.conf allowed to contain this directive

Reference: http://httpd.apache.org/docs/1.3/mod/core.html#virtualhost

Ish Kumar
+2  A: 

G'day,

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

From the Apache 2.2 manual:

server config ... means that the directive may be used in the server configuration files (e.g., httpd.conf), but not within any or containers. It is not allowed in .htaccess files at all.

HTH

cheers,

Rob Wells