.htaccess doesn't work on VirtualHost

2019-09-06 06:45发布

问题:

Since I've setup a wildcard VirtualHost my htaccess files does not work anymore

The http-vhosts.conf

NameVirtualHost *

<VirtualHost *:80>
    ServerName default.dev
    VirtualDocumentRoot /Users/[UserName]/Sites/%-2
    <Directory /Users/[UserName]/Sites/%-2>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

the .htaccess (WordPress default)

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

I can access http://wordpress.dev and also the backend but not a page like http://wordpress.dev/page (causes a 404 error).
I can set the permalink structure to default but I would like to have "nice URLs"

I'm on a local development environment on Mac OS X 10.10 with Apache 2.4

回答1:

Change your VirtualHost definition to:

<VirtualHost *:80>
    ServerName default.dev
    VirtualDocumentRoot /Users/[UserName]/Sites/%-2
    <Directory /Users/[UserName]/Sites>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

i.e, root the directory definition to Sites, not to the virtual directory.