刚刚打开博客文章突然就404了,吓我一大跳。最后上网查询了一下资料发现是伪静态设置的问题。因为使用的是nginx的系统,所以不能设置.htaccess文件,而需要通过设置conf文件来实现伪静态,以下为综合网上资料,实验有效的方法。
打开nginx配置文件nginx.conf,在location段添加下面这一行代码:
location / {
index index.html index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename)
{
rewrite (.*) /index.php;
}
}
一个完整的nginx.conf文件:
server {
listen 80;
server_name blog.derekwei.com;
location / {
index index.html index.htm index.php;
root /www/wwwroot/blog;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:8787;
fastcgi_param SCRIPT_FILENAME /www/wwwroot/blog$fastcgi_script_name;
}
location /ccvita-status {
stub_status on;
access_log off;
}
}
另附上apache下的.htaccess文件设置:
# BEGIN WordPress
IfModule mod_rewrite.c;
RewriteEngine On RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
IfModule;
# END WordPress