【问题标题】:Apache always serving DocumentRoot index.phpApache 始终提供 DocumentRoot index.php
【发布时间】:2012-11-27 23:38:01
【问题描述】:

这可能是一个新手问题,但是...我在 Apache 中配置了一个 SSL 站点,如下所示:

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>

问题是,无论我请求哪个 URL,我总是得到 /var/www/myapp/wwwroot/index.php 的内容(即DocumentRoot 目录中的 index.php)。例如,这些 URL 会发生这种情况:

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

另一方面,如果我在 DocumentRoot 目录中创建一个 index2.php 文件,它会正确显示:

 - https://mysite/index2.php

我猜我的 Apache 配置有问题。

【问题讨论】:

  • 你可以试试AllowOverride none 给我结果吗?
  • 您的根目录中有.htaccess 文件吗?
  • @Eray:没有任何改变,:-(
  • @jaudette:不,我没有 .htaccess

标签: php apache


【解决方案1】:

首先,您可以删除别名中的撇号(不过我认为您的做法是对的)。更改主站点的配置:

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>

到:

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

     </Directory>

您还需要转到 /var/www/myapp/ 并编辑 .htaccess 并将其更改为:

<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>

我假设您在别名指向的 /var/www/myapp/mydir 中有一个 DirectoryIndex 文件(例如 index.php)。让我知道它是否有效

【讨论】:

  • 我改变了你提到的配置,但没有运气。我认为应该有一种方法可以让它在没有 .htaccess 的情况下工作。我在我的笔记本电脑(Mac OS X)上让它像这样工作,但相同的配置在 Ubuntu 中不起作用,这就是我上面描述的
【解决方案2】:

我解决了这个问题,我必须删除别名行第一部分的最后一个斜杠。

这是错误的:

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

这是对的:

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

【讨论】:

    猜你喜欢
    • 2016-09-06
    • 1970-01-01
    • 2012-04-27
    • 2019-08-24
    • 1970-01-01
    • 1970-01-01
    • 2011-01-18
    • 2016-01-11
    • 2011-05-31
    相关资源
    最近更新 更多