Ike本人在设置wordpress的时候,在settings里面发现了Permalink。从这个页面的主要介绍来看,Permalink的作用就是自定义文章的Link,使之更为结构化和友好。

但是当Ike设置了某个除Default之外的某个Permalink的时候,如果点击一篇发表的文章,就会出现Page Not Found的404错误。

经反复查证,Ike发现Permalink与.htaccess和Apache的设置紧密相关。

如果我们在Settings页面的Permalink中就某个选项进行了保存,wordpress在后台就会改写.htaccess:

1
2
3
4
5
6
7
8
9
10
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress

这个.htaccess文件是存放在网页的根目录下的,和wp-config.php存放的位置一样。如果wordpress不能改写此文件,则需要手动改写,但需要注意到的是Ike本人的网页是放在/blog文件夹下的,如果放在别的文件夹下,正确的.htaccess内容可能和上面不一样。

如果成功改写.htaccess,只是成功了一半。因为Ike本人发现即使赋予了后台改写.htaccess的权限,还是不能访问。

有文献报道指出,Apache需要使能rewrite_module才能使得Permalink正常工作。这就需要改写Aapche的配置文件。

运行以下命令:

1
sudo find / -type f -iname "httpd.conf"

找到Apache的配置文件的位置。据相关文献报道,需要做的是将

1
#LoadModule rewrite_module modules/mod_rewrite.so

的注释去掉。

但甚为坑爹的是,Ike发现虚拟机上的Apache配置文件本来就没有把这一行给注释掉。

经过一番查证,这里一篇帖子为我们给出了解决方案的暗示。于是Ike在配置文件下找到了如下若干行:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.
#
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>

...

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All

按照上面配置,再重启Apache即可。大功告成。


留言