0

Here is my virtual host :

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName policy.domain.com
    ServerAlias www.policy.domain.com
    DocumentRoot /policy
    ErrorLog /policy/error.log
    CustomLog /policy/custom.log combined
    <Directory /policy/>
        Options  +IncludesNOEXEC
        AllowOverride None
        Order allow,deny
        allow from all

        # redirect non www to www
        RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]



    </Directory>


</VirtualHost>

I have tried various settngs, but pages at www doesn't seem to appear. Though, the php removal works well when I remove non-www to www condition. To be specific, apache is redirect non www to www but at www it shows server not found error.

akshayb
  • 101
  • 3

1 Answers1

1

Your problem at hand (the actual question), sounds like your DNS entries are not correct for www.policy.domain.com . As a related note.... As per Apache documentation, you should probably not be using mod_rewrite for this.

http://httpd.apache.org/docs/2.2/rewrite/avoid.html#redirect The above page specifies that mod rewrite should not be used for redirecting specific locations to a different subdomain.

proper use likely involves breaking policy.domain.com and www.policy.domain.com into separate virtual hosts and using the redirect directive as appropriate.

finally, given no details on WHY you need this setup, it is recommended that you replace the HTTP_HOST with a static www.policy.domain.com .

and post finally: it appears that tour error_logs may be web readable... Is that by design? Have you taken measures to secure them?

Daniel Widrick
  • 3,488
  • 2
  • 13
  • 27