如何重定向/ path / variables /重写到Apache 2.4中的/index.php/path/variables/?

时间:2014-10-20 18:19:14

标签: php apache .htaccess virtualhost apache2.4

我最近将本地开发服务器从Apache 2.2升级到Apache 2.4(通过Mac OS X 10.10优胜美地)。 Localhost按预期解析,但以下虚拟主机设置不再有效(返回Not Found - The requested URL /subdir was not found on this server.)。

请帮助我将以下内容从Apache 2.2升级到Apache 2.4?

目标是使用PATH变量将所有目录重定向到root。例如:将/abc/def/重定向到/index.php/abc/def/。单独的索引工作正常。但/abc//abc/def/(或任何子目录(路径)不再有效。

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

你能看出为什么这不能正确解决吗?

其他调试:

> ping mylocalsite.local
PING mylocalsite.local (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.115 ms
^C
--- mylocalsite.local ping statistics ---
1 packet transmitted, 1 packet received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.115/0.115/0.115/0.000 ms

> 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

1 个答案:

答案 0 :(得分:1)

确保在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
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
Include /private/etc/apache2/extra/httpd-vhosts.conf

# restart apache