WordPress在Apache和Nginx下的Rewrite规则
- 4961
- Linux
- 9
- super_dodo
- 2014/11/04
WordPress在服务器上面常常需要去除入口文件index.php所以需要根据情况配置相应的Rewrite的规则.常见的有两张服务器apahce和Nginx。常用的Rewrite有两种.htaccess 和在配置文件写规则。
Apache
在Apache下,利用mod_rewrite来实现URL的静态化。
.htaccess的内容如下:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Nginx
其实在Nginx下配置WordPress的Rewrite还是比较简单的,在location /{………………}里面加入下面的代码即可实现。
if (!-f $request_filename){
rewrite (.*) /index.php;
}
下面是Nginx的一个完整的vhost的配置文件
server {
listen 80;
server_name dodobook.net www.dodobook.net;
location / {
index index.html index.htm index.php;
root /www/wwwroot/www.dodobook.net;
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/ccvita.com$fastcgi_script_name;
}
location /ccvita-status {
stub_status on;
access_log off;
}
}
物有所不足 智有所不明 用君之心 行君之意
相关阅读
- 通过Google API客户端访问Google Play帐户报告PHP库
- PHP执行文件的压缩和解压缩方法
- 消息中间件MQ与RabbitMQ面试题
- 如何搭建一个拖垮公司的技术架构?
- Yii2中ElasticSearch的使用示例
热门文章
- 通过Google API客户端访问Google Play帐户报告PHP库
- PHP执行文件的压缩和解压缩方法
- 消息中间件MQ与RabbitMQ面试题
- 如何搭建一个拖垮公司的技术架构?
- Yii2中ElasticSearch的使用示例
最新文章
- 通过Google API客户端访问Google Play帐户报告PHP库
- PHP执行文件的压缩和解压缩方法
- 消息中间件MQ与RabbitMQ面试题
- 如何搭建一个拖垮公司的技术架构?
- Yii2中ElasticSearch的使用示例

