.htaccess无法在VirtualHost上运行

时间:2014-10-30 12:23:25

标签: wordpress .htaccess mod-rewrite

由于我设置了wildcard VirtualHost我的htaccess文件不再起作用

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>

.htaccess (WordPress默认值)

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

我可以访问http://wordpress.dev以及后端,但不能访问http://wordpress.dev/page之类的网页(导致404错误)。
我可以将永久链接结构设置为默认值,但我想拥有“漂亮的URL”

我在使用Apache 2.4的Mac OS X 10.10上使用本地开发环境

1 个答案:

答案 0 :(得分:1)

将您的VirtualHost定义更改为:

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

,即将目录定义根目录定义到Sites,而不是虚拟目录。