本地wordpress网站主页运行良好,但
mod_rewrite
不起作用。因此,主页可以正常工作,但是一旦我单击任何链接,我就会得到 Not Found
。
此错误的日志输出:
[error] [client 127.0.0.1] File does not exist: /Applications/MAMP/htdocs/myweb/my-web-page-that-has-to-work, referer: http://myweb.dev/
根据我的理解,该错误意味着它会查找该特定页面,而不是使用
mod_rewrite
来从数据库获取页面。
httpd.conf
相关内容:
# Virtual hosts, uncommented include
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
...
# AllowOverride All is here
<Directory "/Applications/MAMP/htdocs">
Options All
AllowOverride All
Order allow,deny
Allow from all
XSendFilePath "/Applications/MAMP/htdocs"
</Directory>
httpd-vhosts.conf
相关内容:
<VirtualHost *:80>
DocumentRoot /Applications/MAMP/htdocs
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/myweb"
ServerName myweb.dev
ServerAlias www.myweb.dev
ErrorLog "/private/var/log/apache2/myweb-error_log"
CustomLog "/private/var/log/apache2/myweb-access_log" common
</VirtualHost>
关于如何让它发挥作用有任何线索吗?
首先确保 Apache 加载该模块。请参阅:如何为 Apache 2.2 启用 mod_rewrite
然后将其添加到文件夹内的 .htaccess 文件中
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
</IfModule>
或者像这样将其添加到您的 httpd-vhosts.conf 中。 更正:
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/myweb"
ServerName myweb.dev
ServerAlias www.myweb.dev
ErrorLog "/private/var/log/apache2/myweb-error_log"
CustomLog "/private/var/log/apache2/myweb-access_log" common
<Directory "/Applications/MAMP/htdocs/myweb">
AllowOverride All
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
</IfModule>
</Directory>
</VirtualHost>
现在添加 WP 的重写规则,看看它是否有效。
您可以检查 Apache 是否正在使用文件夹中的 PHP 脚本加载模块。尝试这个并从那里继续。
<?php
if (in_array('mod_rewrite', apache_get_modules())) {
echo "Yes, Apache supports mod_rewrite.";
}
else {
echo "Apache is not loading mod_rewrite.";
}
如果您想为 MAMP 安装启用
mod_rewrite
,您需要执行以下操作:
/Applications/MAMP
,所以我将使用它,但将注释替换为您的/Applications/MAMP/conf/apache/httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so
#LoadModule rewrite_module modules/mod_rewrite.so
LoadModule rewrite_module modules/mod_rewrite.so