WordPress程序伪静态规则
浏览量:182
第一、APACHE环境
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
这个上面代码是适合APACHE环境的,我们只要根目录有一个.htaccess文件,然后丢上上面的文件就可以。
第二、Nginx环境
location / {
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;
}
}
一般虚拟主机都是APACHE环境的,如果是VPS,我们很多都是用的NGINX,这里需要在对应站点的NGINX环境中应用到这个规则,比如/usr/local/nginx/conf/wordpress.conf
设定到这个文件,然后在站点配置文件中引用。
/usr/local/nginx/conf/vhost/hostusvps.com.conf
server {
listen 80;
server_name hostusvps.com www.hostusvps.com;
access_log /home/wwwlogs/hostusvps.com_nginx.log combined;
index index.html index.htm index.php;
include wordpress.conf;
root /home/wwwroot/hostusvps.com;
location ~ .*\.(php|php5)?$ {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
}
上面脚本红色部分就是引用到的伪静态规则。
第三、二级目录规则
如果我们在站点二级目录文件夹单独用一个WP程序,那规则就不同了。
location /hostusvps.com/ {
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 (.*) /hostusvps.com/index.php;
}
}
这里我们对应的是hostusvps.com二级目录文件夹,如果是需要用其他文件夹那就换一个对应名称。修改和添加到根目录的HTACCESS文件中就可以了。


感谢支持与鼓励~