1.apche配置偽靜態(tài):
首先要開啟apache的url_rewrite模塊
(一般默認(rèn)都是開啟的),也就是在httpd.conf( /etc/httpd/conf/httpd.conf)中去掉這句話的注釋LoadModule rewrite_module modules/mod_rewrite.so莉给,httpd.conf中找到AllowOverride驾孔,把AllowOverride None修改成AllowOverride all
在 wordpress 的網(wǎng)站根目錄下的 .htaccess 配置添加(覆蓋)即可:
<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</ifmodule>
原來的:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
2.ngix配置偽靜態(tài)
Nginx 的配置在 vhost 廷雅,目錄根據(jù)主機配置環(huán)境有關(guān)可能不同娱挨,就是域名的 config 文件加入:
操作方法:以下代碼加入到網(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;
}
}
二級目錄下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;
}
}
3. 最后到WP后臺設(shè)置--固定鏈接--固定連接模式推薦為自定義:/%post_id%.html
和 apache 的 .htaccess 不同窄瘟, nginx 的需要重啟 nginx 才能生效衷佃!