Nginx和Apache下WordPress伪静态规则设置
一、nginx伪静态设置:
nginx下Wordpress固定链接的伪静态规则其实特别简单,在nginx配置文件nginx.conf的location段添加一行就OK。
1. 打开nginx配置文件:
# vim /etc/nginx/nginx.conf(此路径根据Linux版本与安装路径会有不同)
2. 在server容器中添加下面这几行
location / { try_files $uri $uri/ /index.php?q=$uri&$args; }
3.检查nginx配置文件是否有错误
# /usr/local/nginx/sbin/nginx -t
4. 重新加载nginx配置文件
# /usr/local/nginx/sbin/nginx -s reload
或 # /etc/init.d/nginx reload
5.重新启动
# /etc/init.d/nginx restart
完成设置。
二、apache伪静态设置:
Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。
1. 检查/etc/httpd/conf/httpd.conf中是否rewrite模块:
LoadModule rewrite_module libexec/mod_rewrite.so
2. 检查Apache是否开启.htaccess支持:
AllowOverride All(默认在httpd.conf文件的338行)
这部分详细配置如下:
<Directory "/var/www/html"> Options Includes ExecCGI FollowSymLinks AllowOverride All Order allow,deny Allow from all RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]
修改完后重启apache生效。