本地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>
有关如何使其发挥作用的任何线索?
答案 0 :(得分:1)
首先确保Apache加载模块。请参阅:How to enable mod_rewrite for Apache 2.2
然后将其添加到文件夹中的.htaccess文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
</IfModule>
或者像这样将它添加到你的httpd-vhosts.conf中。的 CORRECTED:强>
<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.";
}
答案 1 :(得分:0)