简体   繁体   中英

Apache always serving DocumentRoot index.php

This might be a newbie question but... I configured a SSL site in Apache as follows:

NameVirtualHost *:443

<VirtualHost *:443>
    ServerName dev.wonnova.com
    DocumentRoot "/var/www/myapp/wwwroot"

    SSLEngine on

    SSLProtocol -all +TLSv1 +SSLv3
    SSLCipherSuite HIGH:MEDIUM:!aNULL:+SHA1:+MD5:+HIGH:+MEDIUM

    SSLCertificateFile /etc/apache2/ssl/mycert.crt
    SSLCertificateKeyFile /etc/apache2/ssl/mycert.key

    <IfModule mime.c>
        AddType application/x-x509-ca-cert      .crt
        AddType application/x-pkcs7-crl         .crl
    </IfModule>

    Alias /mydir/ "/var/www/myapp/mydir"

    <Directory "/var/www/myapp/mydir">
        SSLRequireSSL
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride all
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

The thing is that no matter which URL I request, I always get the contents of /var/www/myapp/wwwroot/index.php (ie index.php in DocumentRoot directory). It happens for these URLs, as an example:

 - https://mysite/index.php
 - https://mysite/mydir/index.php
 - https://mysite/mydir/style.css
 - https://mysite/mydir/script.js

On the other hand, if I create an index2.php file in DocumentRoot directory, it shows correctly:

 - https://mysite/index2.php

I guess there's something that is wrong with my Apache configuration.

First of all you can remove the apostrophes from the Alias (I think yours is right though). Change the configuration of your main site:

Alias /mydir/ "/var/www/myapp/mydir"

    <Directory "/var/www/myapp/mydir">
        SSLRequireSSL
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride all
        Order allow,deny
        Allow from all
    </Directory>

to:

Alias  /mydir /var/www/myapp/mydir
    <Directory /var/www/myapp/mydir>
         SSLRequireSSL
         Allow From all
         Options +Indexes FollowSymLinks Includes ExecCGI
         AllowOverride all 

     </Directory>

Also you need to go to /var/www/myapp/ and edit the .htaccess and change it to:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /mydir/
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /mydir/index.php [L]
</IfModule>

I assume you have a DirectoryIndex file (eg index.php) in the /var/www/myapp/mydir to which the alias is pointed. Let me know if it works

I solved the issue, I had to remove the last slash of the first part of the Alias line.

This was wrong:

Alias /mydir/ "/var/www/myapp/mydir"

This is right:

Alias /mydir "/var/www/myapp/mydir"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM