wordpress的偽靜態(tài)規(guī)則是根據(jù)服務(wù)器環(huán)境來(lái)設(shè)置的,不同的php環(huán)境有不同的偽靜態(tài)設(shè)置方法,常見(jiàn)的php環(huán)境有 apache和nginx ,以下分別就這兩種環(huán)境做偽靜態(tài)設(shè)置。
apache規(guī)則:
首先要開(kāi)啟apache的url_rewrite模塊(一般默認(rèn)都是開(kāi)啟的),也就是在httpd.conf中去掉這句話的注釋LoadModule rewrite_module modules/mod_rewrite.so,httpd.conf中找到AllowOverride,把AllowOverride None修改成AllowOverride all
網(wǎng)站根目錄下要有 .htaccess 文件,然后將下面的代碼復(fù)制進(jìn)去。
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
wordpress在apache環(huán)境下二級(jí)目錄建站偽靜態(tài)操作方式同上。
nginx規(guī)則:
操作方法:以下代碼加入到網(wǎng)站的配置文件 xxxx.conf 中的 server{} 中。
根目錄下wordpress的偽靜態(tài)規(guī)則:
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;
}
}
二級(jí)目錄下wordpress的偽靜態(tài)規(guī)則:
注意將以下代碼中的“二級(jí)目錄名”換成自己的真實(shí)二級(jí)目錄名。
location /二級(jí)目錄名/ {
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 (.*) /二級(jí)目錄名/index.php;
}
}