当根目录完美解析时,如何让 Apache 2.4 localhost 子目录进行解析?

当根目录完美解析时,如何让 Apache 2.4 localhost 子目录进行解析?

根据这里的其他答案,我能够让 Apache 加载本地主机页面:

2.2配置:

Order allow,deny
Allow from all

2.4配置:

Require all granted

这对于类似本地主机页面非常有用mylocalsite.local(返回完整页面,包括嵌套目录中所需的资产,如 css 和图像)。

但是当我尝试访问子目录时,mylocalsite.local/subdir它会返回Not Found - The requested URL /subdir was not found on this server.

请参阅下文以了解我的虚拟主机的配置方式。显然mylocalsite.local设置为127.0.0.1in/etc/hosts才能让我走到这一步。

<VirtualHost *:80>
    ServerName mylocalsite.local
    ServerAlias www.mylocalsite.local mylocalsite_alt.local

    <Directory /Users/my_username/Sites/mylocalsite/html>
        AllowOverride none
        Options all
        Require all granted
        Deny from none

        <IfModule mod_rewrite.c>
            Options +FollowSymLinks -MultiViews
            RewriteEngine On

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

            # Redirect all /img/abc to /img/index.php/abc
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^img/(.*) img/index.php/$1 [L]

            # redirect all directories to root using PATH variables
            # Ex. /abc/def/ redirects to /index.php/abc/def/
            RewriteCond %{REQUEST_URI} !=/server-status
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule (.*) index.php/$1 [L]
        </IfModule>
    </Directory>

    DocumentRoot /Users/my_username/Sites/mylocalsite/html
</VirtualHost>

你能知道为什么这个问题没有被正确解决吗?

其他调试:

> sudo apachectl configtest
Syntax OK

> httpd -S
VirtualHost configuration:
*:80                   is a NameVirtualHost
     default server sandbox (/private/etc/apache2/vhosts/virtual_hosts.conf:8)
     port 80 namevhost sandbox (/private/etc/apache2/vhosts/virtual_hosts.conf:8)
             alias sandbox
     port 80 namevhost mylocalsite.local (/private/etc/apache2/vhosts/virtual_hosts.conf:20)
             alias www.mylocalsite.local
             alias mylocalsite_alt.local
ServerRoot: "/usr"
Main DocumentRoot: "/Users/my_username/Sites"
Main ErrorLog: "/private/var/log/apache2/error_log"
Mutex default: dir="/private/var/run/" mechanism=default 
Mutex mpm-accept: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex proxy: using_defaults
PidFile: "/private/var/run/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="_www" id=70 not_used
Group: name="_www" id=70 not_used

在 Mac OS X Mavericks 10.9 中一切都运行正常。

答案1

我在这里找到了一个可行的解决方案http://mallinson.ca/osx-web-development/

请注意优胜美地的部分!

确保 httpd.conf 中的以下内容未注释:

LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
LoadModule php5_module libexec/apache2/libphp5.so
LoadModule alias_module libexec/apache2/mod_alias.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
Include /private/etc/apache2/extra/httpd-vhosts.conf

相关内容