当 URL 不完整时,Apache 提供 css 或 js

当 URL 不完整时,Apache 提供 css 或 js

如果我浏览:http://example.com/或者http://example.com/index.php我得到了想要的页面,但如果我浏览http://example.com/index(或任何没有扩展名的页面),它会在纯文本文件视图中显示 CSS 或有时显示 JS。Apache 2.4.7 Ubuntu 14.04 LTS。知道为什么会发生这种情况吗?我搜索了很久 - 没有运气。

我添加了AddType application/x-httpd-php .php .htmlmime 类型,但似乎对问题没有影响。

这是我的 default.conf:

<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /srv/www/html
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /srv/www/html>
    AddType audio/ogg .oga
    AddType video/ogg .ogv
    AddType application/ogg .ogg
    AddType audio/mpeg .mp3
    AddType application/x-httpd-php .php .html

    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>
 .. rest is just log and pw protect etc

更改了 apache.conf 的部分内容:

  <Directory />
            ExpiresActive On
            ExpiresDefault "access plus 12 hours"
            ExpiresByType application/javascript "access plus 10 months"
            ExpiresByType image/jpg "access plus 10 months"
            ExpiresByType image/jpeg "access plus 10 months"
            ExpiresByType image/gif "access plus 10 months"
            ExpiresByType image/png "access plus 10 months"
            ExpiresByType text/css "access plus 10 monthss"
            ExpiresByType image/x-icon "access plus 10 months"
            FileETag MTime Size
    </Directory>

以下是已安装模块的列表:

 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cache_module (shared)
 cache_disk_module (shared)
 cgi_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 expires_module (shared)
 filter_module (shared)
 headers_module (shared)
 lbmethod_byrequests_module (shared)
 mime_module (shared)
 mpm_prefork_module (shared)
 negotiation_module (shared)
 pagespeed_module (shared)
 php5_module (shared)
 proxy_module (shared)
 proxy_balancer_module (shared)
 proxy_http_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 slotmem_shm_module (shared)
 status_module (shared)

答案1

看起来它是 vhost.conf 或 apache.conf 文件中名为 Multiviews 的选项。

<Directory /srv/www/mysite/html/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
</Directory>

删除后MultiViews问题解决。

虽然我不知道为什么 apache 会选择 index.js 而不是 index.php。

相关内容